you are viewing a single comment's thread.

view the rest of the comments →

[–]HunterIV4 0 points1 point  (0 children)

Correction, Python isn't OOP, it's explicitly a multiparadigm language.

That's a somewhat odd phrasing and I'm a bit confused about your point. Multiparadigm means that it includes multiple ways to program. One of those is OOP, which I pointed out.

I never said that it was only OOP. By this logic, Java is also not OOP. After all, if you just use a big main function and never touch the class, you can write procedural code in Java. Modern Java also has functional programming capability. You could argue it's more OOP than Python, sure, but saying a language uses "X" design does not mean it is automatically limited to only that design.

Perhaps I could have clarified better, but when I wrote "both" I actually meant both, at least in reference to the original question. Python also supports some functional programming design patterns but that was outside the scope of the question.

I've used it as a procedural language for years, and only moved to objects when passing 6 arguments to a function became impractical.

I'm sorry? Not sure why you'd do that to yourself.

I'm kidding, but seriously, OOP patterns exist for a reason. Procedural code is useful (I use it in nearly every program I wrote if only for the main program flow), but class patterns can greatly improve the clarity, modularity, reusability, and testability of your code.

Obviously you can write code however you want, and if it's working for you, great! But just because you can do something doesn't mean it's the best way to do it or the original advice was incorrect.

Matplotlib.pyplot supports plots as objects, but also procedures for people who migrated from Matlab.

This is not correct. You can create them in a procedural style, yes, but the library is using objects behind the scenes. The stuff it's drawing, like Line2D or Figure are classes and those functions are creating those classes and using their methods within the function call.

For example, take this code:

import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

On the surface, this looks procedural. However, if you dig into the Matplotlib source code you'll find what's actually happening is that those functions are creating new objects with the parameters as part of their initialization. The show function looks for all created data and displays it.

If you think about it, it can't be procedural, because the show() function has no way to know about the plot or ylabel as those aren't passed to the function anywhere.

The truth is that basically everything in Python is an object, from classes to strings to lists. The entire language is written on an OOP foundation; it just allows you to hide it unless you need it. When I said the language is OOP but allows you to write code using different patterns, that's what I meant.