[–] 1 point 1 year ago (3 children)

I disagree. You can write a lot of high quality Python code (yeah it exists) before you need to use inheritance. If you're reaching for inheritance as the solution to all complexity, GoF-style, then you're doing it wrong.

It's an occasionally useful tool that has its place, not something you should instinctively reach for.

  • source
  • parent
  • context
  • [–] [S] 2 points 1 year ago (4 children)

    I use external packages for compiled languages. For scripting languages like Python, it makes it ab it harder to use. Because people are forced to install dependencies. I don't like that (unless its a shell script, but that is by its nature a dependency hell).

    And for Python, I usually deliver the script as a single .py file, without requirements or special instructions, no typical file structure as well. And your argument just because other popular packages use a specific library does not mean I have to use it too. I don't care what libraries other popular packages use, at least in context to my program / script.

  • source
  • parent
  • context
  • [–] 1 point 1 year ago

    Yeah that's a great point -- the dataframe is in a sense a class or object standardized for data analysis. Its flexibility (like being able to store arrays or dicts even) obviates the need in most cases for a user-written class.

  • source
  • parent
  • context
  • [–] 1 point 1 year ago* (5 children)

    What is the root basis of your external package reluctance? Please explain cuz that's really where the juicy story lies.

    As technologists things change and advance and we have to adapt (or not) with the times. Maintaining the universe by ourselves is impossible, instead almost all of our tech choices are from what's available. And only if/when that is insufficient do we roll up our sleeves.

    More and more packages are using click. So there is a good chance if you look at your requirements .lock file that it's already a transitive dependency from another dependency.

    Or said another way, show me 5 popular packages that use argparse and not click and use dataclasses and not attrs

  • source
  • parent
  • context
  • [–] 6 points 1 year ago

    Well, it's more procedural than object-oriented because it's easier to avoid object-oriented programming than procedural code :D

    (Note: I wouldn't call defining classes OOP until you start using inheritance. Overriding __str__ and stuff might count, but not a lot to me.)

    Personally, as time goes on, I use inheritance less.

  • source
  • [–] 0 points 1 year ago

    Computers only have one language and one data type. Everything else is a construct, which we can build up into a beautiful thing: a mathematics that exists in the real world instead of the pure realm of axioms and symbols, and because it's purely our own creation and not the universe's, we know it from the fundamentals and don't have to struggle with all the unknowns of physics, which presents us with very different, more mysterious mathematical objects to interact with instead.

  • source
  • parent
  • context
  • [–] 8 points 1 year ago (1 child)

    You can write Python in an OOP style if you want to, and you sort of have to in the case of using certain libraries, but it's mostly optional and imho rather ugly.

  • source
  • [–] 3 points 1 year ago

    It supports both and depending on the situation its more procedural or more object oriented. Do you consider the standard library as part of the language and are you forced to use it? Then certainly the object oriented parts of the language would be forced to use and therefore it is object oriented. Or do you only evaluate the language and its features itself? In that case, Python supports object oriented programming with classes and objects, but you are not forced to use it.

    Are we talking about the language features itself or the produced programs with it in the real world?

    So regardless if you look at the language itself or the common standard library that most Python programs use, objects and classes are an part of the language. Even if you write simple procedural scripts, does not take away that Python itself is a more object oriented programming language.

  • source
  • [–] 4 points 1 year ago

    As with most script languages, you can hit the ground running in a very procedural sort of way, as you don't even have to define a main entry point. You just start coding.

    But Python certainly has an object model. If I'm not mistaken, everything in Python is an object. Like even functions.

    I suppose there are some aspects of the class implementation that feel a little tacked on? Like the way you need to manage the self reference manually where it may be implicitly handled for you in other languages. At least the way you call super() now is a lot less kludgy.

    One thing I miss a bit in Python is method overloading. In a general sense, function overloading is not an OOP feature per se, but I find it useful in OOP, particularly with object initializers. You can sort of achieve it with @functools.singledispatch but it's pretty janky. For initialization, I prefer keeping the __init__ method pretty rudimentary and writing factory functions to do more complex initializations. And with @dataclass, you can forego writing an __init__ altogether if you do it that way.

  • source
  • [–] 9 points 1 year ago (4 children)

    The question is invalid!

    Write the code that makes sense for your problem. This is not religion where choosing the wrong thing can land you in hell for eternity or whatever it is your gods will do if they don't like you. You should be mixing OO, functional, and procedural code all the time as each does some things well and some things poorly. Of course don't create a mess by the mix, but good code has a need for all 3 styles. (IIRC there are more styles the good code needs, but I can't think of what it might be at the moment)

  • source
  • [–] 2 points 1 year ago

    Depends also on what you use python for. If you build a whole piece of software, you will be using objects. But many teams use Java for the business logic and python as a scripting language to call some api, or automate a task. In those cases python will be used procedurally, as a nicer bash basically.

  • source
  • parent
  • context
  • The language supports both, so it really depends on the user. The standard library doesn't have a clear preference, and uses both approaches, along with functional style.

    So I'll say both, and my preference is a hybrid of functional and procedural.

  • source
  • [–] 12 points 1 year ago (2 children)

    For me it depends on the use case. If I'm designing something with an interface for someone downstream to use, I'll usually define (data)classes even if I have a functional interface.

    For data science/modeling/notebooks I usually wouldn't define classes.

    I think it also depends on your team; if everyone else is a functional programmer and you're writing classes or vice versa, this will undoubtedly create frictions.

  • source
  • [–] 15 points 1 year ago (7 children)

    I used to struggle with OOP because all the explanations I saw were in terms of metaphors of real world objects. Once i started seeing OOP as a way to better structure your code, it all fell into place. If you do anything marginally complex, OO is the way to go.

  • source
  • [–] [S] 2 points 1 year ago (6 children)

    Nice. There is a reason why the standard library of Python does not get rid of optparse. optparse was I think marked to be removed in the future, but its no longer deprecated and will stay in the library.

    Click looks good and I would have looked in more detail. The problem to me is, it is a dependency. I usually write and try to write Python programs without external library dependency, unless it is absolutely necessary (like GUI or BeautifulSoup). Click "might" be a better alternative, but it is "only" something that does it a little bit better. This is not a reason for me to use an external library.

  • source
  • parent
  • context
  • [–] 6 points 1 year ago (2 children)

    Any language can be procedural if you insist (maybe Haskell will fight you?), creating objects is a design choice to organize the code better. Any project beyond a few hundred lines of code should probably use objects.

    The language itself can be considered object oriented since it allows the typical OOP patterns.

  • source
  • view more: β€Ή prev next β€Ί