This is a question for people more experienced with Python, but everybody feel free to answer if you feel like you can provide something decent to the discussion.

Also feel free to explain why you feel that way and your experiences with Python and the paradigms.

  • Diplomjodler@lemmy.world
    link
    fedilink
    arrow-up
    15
    arrow-down
    2
    ·
    10 months ago

    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.

    • Custodian6718@programming.devOP
      link
      fedilink
      English
      arrow-up
      6
      arrow-down
      2
      ·
      10 months ago

      I do agree except for the last sentence because I do not think that OOP is the silver bullet for everything.

      • Diplomjodler@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        10 months ago

        I was talking about Python specifically. And no, of course it’s not a silver bullet. It’s a solution for structuring your code base in a way that lets you not lose track of what does what.

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      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.

      • Sleepkever@lemm.ee
        link
        fedilink
        arrow-up
        4
        ·
        10 months ago

        OOP not just inheritance. Object oriented programming starts with structuring things in objects, like the name suggests. It quickly has a place in anything more then a few hundred lines of code.

      • Diplomjodler@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        10 months ago

        I rarely use inheritance. Like i said, I see OOP mainly as a way to achieve cleaner code structure and better readability. That last point is really my main concern.

  • danzania@infosec.pub
    link
    fedilink
    arrow-up
    9
    ·
    10 months ago

    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.

  • solrize@lemmy.ml
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    10 months ago

    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.

  • Tja@programming.dev
    link
    fedilink
    arrow-up
    8
    ·
    10 months ago

    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.

    • Custodian6718@programming.devOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      10 months ago

      Obviously (almost) in any language code can be forcefully programmed the way you want, yes. But that is not how we normally code now is it? Usually languages & their community lean more towards certain paradigms than others.

      • Tja@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        10 months 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.

  • koala@programming.dev
    link
    fedilink
    arrow-up
    6
    ·
    10 months 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.

  • thingsiplay@beehaw.org
    link
    fedilink
    arrow-up
    3
    ·
    10 months 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.

  • MoonMelon@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    10 months ago

    Used it a ton in the art departments of vfx and game dev. Im talking about the tools that make assets, not the game engine or a runtime scripting language. More like the stuff launching and running in Maya, or Houdini, or Substance, etc.

    Most of this is already highly OO, and there’s a lot of interaction with C++. Python is the perfect language for this. There’s a lot of rapid interation and gluing many different services and data together. Also you’re waiting on file IO or some massive scene graph update all the time so having the tools be slightly slower doesn’t matter. Also, at least in vfx, there’s mixed Linux/Windows/Mac and it’s great for that. ALSO art teams (unlike the programming team) have people who may not be super technical, and Python let’s them write tools and scripts more easily. They don’t even have to understand OO but you can say “copy this class template and implement these two methods” and they can write tools that “work” in the pipeline.

    It’s honestly a godsend. Before the industry settled on Python, every program had its own proprietary scripting language and some were quite limited. Their C++ APIs are all different, of course. So now everyone just ships with a Python interpreter, you manage launching each app so you can control PYTHONPATH and you’re golden.

  • Corbin@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    10 months ago

    In terms of the standard principal programming paradigms, Python is on the right-hand side in the “Shared state” column. Note two interesting things: first, Python’s box is represented by Java and OCaml; second, the box has two labels, “Sequential object-oriented programming” and “Stateful functional programming”. Python is technically a prototype-based language like ECMAScript, but it can be seen as either object-oriented or functional depending on whether we think of prototypes as classes or closures respectively.

    Note that unlike “Imperative programming”, represented by Pascal and C, Python has closures. It does have closure quirk, also called lambda quirk, which ruins an otherwise-lexically-scoped language, but folks with lots of Python experience are used to working around closure quirk. Python functions are not procedures; they are sugar for objects with a .__call__() method.

    If this is your first time with the principal paradigms, please keep in mind the following quotes. First, from the associated book:

    More is not better or worse than less, just different.

    That is, Turing-completeness doesn’t have a canonical set of computational features. Second, from the chart PDF:

    Two languages that implement the same paradigm can nevertheless have very different “flavors” for the programmer, because they make different choices on what programming techniques and styles to facilitate.

  • sugar_in_your_tea@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    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.

  • grue@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    I like writing Python in a relatively Functional way most of the time, with lots of list and dict comprehensions.