Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Object oriented programming in Python be like:

Object oriented programming in Python be like:

Scheduled Pinned Locked Moved Programmer Humor
49 Posts 28 Posters 1 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • eager_eagle@lemmy.worldE [email protected]

    nah, I'm never complaining about self in Python after having tried the this and that nonsense in JS.

    oh, you're using a named function instead of an arrow fn? Guess what, this is not what it used to be anymore.

    J This user is from outside of this forum
    J This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #29

    Oh, you assigned a method to a variable before calling it? Congratulations, this is now undefined.

    P 1 Reply Last reply
    16
    • F [email protected]

      Not like C# is all that much better. So much garbage in the fundamentals just because it was done that way at the start and "they can't change it now". The best example is the IList interface.

      Theoretically this interface exposes both index-based access and collection-like modifications and as such would be perfect in a function if you need those two features on a type. In reality you can't use it as a function parameter because half the official types implementing IList aren't modifiable and throw a runtime error. E.g Arrays

      kogasa@programming.devK This user is from outside of this forum
      kogasa@programming.devK This user is from outside of this forum
      [email protected]
      wrote on last edited by [email protected]
      #30

      That's a footgun sure but at least you can avoid it once you're aware of the problem.

      I never write function signatures with mutable interfaces. It's always IEnumerable, IReadOnlyCollection, or IReadOnlyList; otherwise, use a concrete type. The latter is typical for private/protected methods that are called with instance members of a concrete type rather than public interfaces. If you want to mutate an object, you should own it. Public methods are invoked with data not owned by the instance.

      For example, a lot of extension methods in LINQ have a signature IEnumerable<T> --> IEnumerable<T>, and internally the first thing they do is call .ToList(). The interface makes minimal assumptions about the input data, then puts it into a concrete type you can manipulate efficiently. You can similarly define a method for IReadOnlyList and explicitly make it mutable via .ToList(), rather than use IList and check .IsReadOnly. Both ensure correctness but the former does it at the type level, at design time, instead of relying on runtime checks.

      C# is old and full of oldness. But it's also an excellent language that can be written beautifully if you know how. And there's lots of great code to learn from in the open-source dotnet core runtime repo and related projects.

      F 1 Reply Last reply
      1
      • A [email protected]

        You're right in that OOP feels very shoehorned in with Python. But not every project has a Linus Torvalds to publicly humiliate horrible ideas and implementations.

        F This user is from outside of this forum
        F This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #31

        In what way does OOP feel shoehorned in with Python?
        I ask since that is not my own impression of the language.

        Would you also be willing to share what language(s) you feel do(es) OOP without it being shoehorned in?

        A A 2 Replies Last reply
        6
        • P [email protected]

          Reminds me of java

          I have Toolkit toolkit = Toolkit.getDefaultToolkit(); seared into my brain. Then there were the bean factories…

          M This user is from outside of this forum
          M This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #32

          Now my brain wants to relate Java somehow to beancounters.

          P 1 Reply Last reply
          2
          • S [email protected]

            Even regular Rust code is more "exciting" than Python in this regard, since you have a choice between self, &self, and &mut self. And occasionally mut self, &'a self, and even self: Box<Self>. All of which offer different semantics depending on what exactly you're trying to do.

            D This user is from outside of this forum
            D This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #33

            I'll add that 100% of the above is understood by the compiler. Unlike Python or JavaScript where you don't know how bad you have it until the program is already running.

            L 1 Reply Last reply
            6
            • A [email protected]

              Write a new method, make sure to reference self first. Write a new method, make sure to reference self first. Call the method, make sure to reference self first.

              Yeah, I can see it.

              A This user is from outside of this forum
              A This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #34

              You don't reference self when calling a method, what on earth are you talking about?
              You start with the instance when calling the method, like most/all other OOP languages.

              Also there are benefits with the explicit self/this to access instance properties.
              In C++ you need to make sure all class properties/members have a naming scheme that does not conflict with potential parameter names or other names of other variables.

              1 Reply Last reply
              3
              • F [email protected]

                In what way does OOP feel shoehorned in with Python?
                I ask since that is not my own impression of the language.

                Would you also be willing to share what language(s) you feel do(es) OOP without it being shoehorned in?

                A This user is from outside of this forum
                A This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #35

                Yeah, some weird accusations. Python has had classes since its inception (1.0).

                Also the image in the post makes no sense. It shows multiple (Spidey) instances all pointing to each other which is not how self works.
                self is just a parameter that may contain different instances depending how it was called. This is also true for any other parameters in any function, each time a function is called it may have a different instance.

                1 Reply Last reply
                3
                • A [email protected]
                  This post did not contain any content.
                  I This user is from outside of this forum
                  I This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #36

                  Break convention

                  `
                  class foo:
                  def init(cunt, bar):
                  cunt.bar=True

                  `

                  1 Reply Last reply
                  9
                  • F [email protected]

                    Not like C# is all that much better. So much garbage in the fundamentals just because it was done that way at the start and "they can't change it now". The best example is the IList interface.

                    Theoretically this interface exposes both index-based access and collection-like modifications and as such would be perfect in a function if you need those two features on a type. In reality you can't use it as a function parameter because half the official types implementing IList aren't modifiable and throw a runtime error. E.g Arrays

                    T This user is from outside of this forum
                    T This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #37

                    Oh god, I didn't knew that. That's funny.

                    1 Reply Last reply
                    0
                    • eager_eagle@lemmy.worldE [email protected]

                      it's common practice as a workaround to save this when changing contexts, since this may change under you, in callbacks and such

                      J This user is from outside of this forum
                      J This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #38

                      Kotlin:

                      [email protected]
                      
                      1 Reply Last reply
                      1
                      • kogasa@programming.devK [email protected]

                        That's a footgun sure but at least you can avoid it once you're aware of the problem.

                        I never write function signatures with mutable interfaces. It's always IEnumerable, IReadOnlyCollection, or IReadOnlyList; otherwise, use a concrete type. The latter is typical for private/protected methods that are called with instance members of a concrete type rather than public interfaces. If you want to mutate an object, you should own it. Public methods are invoked with data not owned by the instance.

                        For example, a lot of extension methods in LINQ have a signature IEnumerable<T> --> IEnumerable<T>, and internally the first thing they do is call .ToList(). The interface makes minimal assumptions about the input data, then puts it into a concrete type you can manipulate efficiently. You can similarly define a method for IReadOnlyList and explicitly make it mutable via .ToList(), rather than use IList and check .IsReadOnly. Both ensure correctness but the former does it at the type level, at design time, instead of relying on runtime checks.

                        C# is old and full of oldness. But it's also an excellent language that can be written beautifully if you know how. And there's lots of great code to learn from in the open-source dotnet core runtime repo and related projects.

                        F This user is from outside of this forum
                        F This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #39

                        Functional programming fixes the problem by simply not making it OO anymore, and while I'm personally a big fan of the paradigm there are situations where an OO approach is preferable (or even only to conform to a project's existing way of doing things).

                        kogasa@programming.devK 1 Reply Last reply
                        1
                        • F [email protected]

                          Functional programming fixes the problem by simply not making it OO anymore, and while I'm personally a big fan of the paradigm there are situations where an OO approach is preferable (or even only to conform to a project's existing way of doing things).

                          kogasa@programming.devK This user is from outside of this forum
                          kogasa@programming.devK This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #40

                          What I described isn't necessarily functional. This is just a principle for ensuring objects represent clear and well-defined contracts. The idea is that to mutate something, you should own it; that means interfaces / public APIs, which can be called externally, should take immutable arguments. You can still mutate instance members internally because those are owned by the instance. If mutation is really necessary between two objects then it should be coordinated by an object owning them both.

                          1 Reply Last reply
                          0
                          • D [email protected]

                            I'll add that 100% of the above is understood by the compiler. Unlike Python or JavaScript where you don't know how bad you have it until the program is already running.

                            L This user is from outside of this forum
                            L This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #41

                            At least python has a decent runtime typing system

                            JS's type system feels like what you'd get by giving a monkey access to unlimited cocaine and a computer

                            1 Reply Last reply
                            7
                            • J [email protected]

                              Oh, you assigned a method to a variable before calling it? Congratulations, this is now undefined.

                              P This user is from outside of this forum
                              P This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #42

                              Yes. There's no telling what this is. this could be anything. We tried to keep track of this, but no one knows when this will change.

                              J 1 Reply Last reply
                              3
                              • P [email protected]

                                Yes. There's no telling what this is. this could be anything. We tried to keep track of this, but no one knows when this will change.

                                J This user is from outside of this forum
                                J This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #43

                                I used to be with this, but then they changed what this was.

                                Now what I'm with isn't this, and what's this seems weird and scary to me.

                                This'll happen to you!

                                1 Reply Last reply
                                5
                                • G [email protected]

                                  that's because anyone who develops oop in Python is mentally ill.

                                  Python is a scripting language, not to be confused with an actual programming language. Like everything else in development over the last decade, newbs are just shoehorning whatever is hot into the language because nobody is stopping them.

                                  D This user is from outside of this forum
                                  D This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by [email protected]
                                  #44

                                  that’s because anyone who develops oop in Python is mentally ill.

                                  Hard disagree there. I would argue that most "multi-paradigm" languages converge on the same features, given enough time to iterate. It's not necessarily about hot-sauce. I honestly think its about utility and meeting your userbase where their heads are.

                                  G 1 Reply Last reply
                                  0
                                  • F [email protected]

                                    Not like C# is all that much better. So much garbage in the fundamentals just because it was done that way at the start and "they can't change it now". The best example is the IList interface.

                                    Theoretically this interface exposes both index-based access and collection-like modifications and as such would be perfect in a function if you need those two features on a type. In reality you can't use it as a function parameter because half the official types implementing IList aren't modifiable and throw a runtime error. E.g Arrays

                                    S This user is from outside of this forum
                                    S This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #45

                                    Embrace the holy light of Dart

                                    1 Reply Last reply
                                    0
                                    • D [email protected]

                                      that’s because anyone who develops oop in Python is mentally ill.

                                      Hard disagree there. I would argue that most "multi-paradigm" languages converge on the same features, given enough time to iterate. It's not necessarily about hot-sauce. I honestly think its about utility and meeting your userbase where their heads are.

                                      G This user is from outside of this forum
                                      G This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #46

                                      I honestly think its about utility and meeting your userbase where their heads are.

                                      then the Python userbase must have their heads shoved up their ass.

                                      1 Reply Last reply
                                      1
                                      • M [email protected]

                                        Now my brain wants to relate Java somehow to beancounters.

                                        P This user is from outside of this forum
                                        P This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #47

                                        Well it is owned by Oracle now

                                        1 Reply Last reply
                                        0
                                        • F [email protected]

                                          In what way does OOP feel shoehorned in with Python?
                                          I ask since that is not my own impression of the language.

                                          Would you also be willing to share what language(s) you feel do(es) OOP without it being shoehorned in?

                                          A This user is from outside of this forum
                                          A This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #48

                                          I was looking to see if there are equivalents to Java's private and protected members, and it looks like Python's answer to that is just throw one or two underscores in front of things to do that. And it doesn't really do anything, more of just a naming convention. To me that feels like a basic OO structure that is shoehorned into Python.

                                          F 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups