• Bye@lemmy.world
    link
    fedilink
    arrow-up
    51
    arrow-down
    2
    ·
    8 months ago

    The day I learned that Linus shares my disdain for all things OOP was such a good day for me.

    • ADTJ@feddit.uk
      link
      fedilink
      arrow-up
      74
      arrow-down
      1
      ·
      8 months ago

      Me, when Linus’ opinion is different to mine: “Linus has such weirdly strong opinions about this

      Me when Linus’ opinion is the same as mine: VINDICATION

    • evranch@lemmy.ca
      link
      fedilink
      arrow-up
      22
      ·
      8 months ago

      I feel the OOP debate got a bit out of hand. I hate OOP as well, as a paradigm.

      But I love objects. An object is just a struct that can perform operations on itself. It’s super useful. So many problems lend themselves to the use of objects.

      I’ve been writing a mix of C and C++ for so long I don’t even know where the line is supposed to be. It’s “C with objects”. I probably use only 1% of the functionality of C++, but that 1% is a huge upgrade from bare C IMO.

      • namingthingsiseasy@programming.dev
        link
        fedilink
        arrow-up
        12
        ·
        8 months ago

        Agreed. Objects are nice and a great way to program. Composition is great. Traits/interfaces are great. Namespaces are great. Objects are a really nice way to reap the benefits of principles like these.

        But then there are aspects of OOP that absolutely suck, like inheritance. I hate inheritance. The rules get very confusing very quickly. For example, try understanding overriding of methods. Do I need to call the superclass method or not? If not, does it get called automatically? If so, in what order? How do these rules change for the constructor? Now repeat this exercise for every OOP language you use and try not to mix them up… Java, C++, Python, etc.

        Fortunately, it feels like we rely on inheritance less and less these days. As an example, I really like how Java allows you to implement Runnable these days. Before, if you wanted to run a thread, you needed a separate object that inherited Thread. And what if that object needs to inherit from another one too? Things would get out of hand quickly. (This is a very old example, but with lambdas and other new features, things are getting even better now.)

        Anyway, long story short, I think OOP is a complicated way to achieve good principles, and there are simpler ways to achieve those principles than a full OOP implementation.

        • CapeWearingAeroplane@sopuli.xyz
          link
          fedilink
          arrow-up
          1
          ·
          8 months ago

          I’ve seen this thing where people dislike inheritance a lot, and I have to admit that I kind of struggle with seeing the issue when it’s used appropriately. I write a bunch of models that all share a large amount of core functionality, so of course I write an abstract base class in which a couple methods are overridden by derived models. I think it’s beautiful in the way that I can say “This model will do X, Y, Z, as long as there exists an implementation of methods A, B, C, which have these signatures”, then I can inherit that base class and implement A, B, and C for a bunch of different cases. In short, I think it’s a very useful way to express the purpose of the code, without focusing on the implementation of specific details, and a very natural way of expressing that two classes are closely related models, with the same functionality, as expressed by the base class.

          I honestly have a hard time seeing how not using inheritance would make such a code base cleaner, but please tell me, I would love to learn.

      • AeonFelis@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        8 months ago

        I think the problem with OOP is something you can see whenever legislation is linked with prestige (it happens a lot in real life). The number of good possible rules is quite limited, and the number of people who want to make a name for themselves by championing them seems to be infinite. If you can’t find a good rule to claim as your own, you have to pick a bad rule and try to gaslight people into thinking it’s a necessary and beneficial. Enough people do that, and we end up with modern OOP.

    • jabjoe@feddit.uk
      link
      fedilink
      English
      arrow-up
      14
      arrow-down
      1
      ·
      8 months ago

      He is is OK with OOP. The Linux kernel is full of OPP C, but he doesn’t like C++

        • jabjoe@feddit.uk
          link
          fedilink
          English
          arrow-up
          3
          ·
          8 months ago

          Look at the kernel code. It’s full of OOP C. There absolutely are objects in the kernel.

          • refalo@programming.dev
            link
            fedilink
            arrow-up
            3
            ·
            8 months ago

            Yea but all that function pointer indirection can actually hurt performance (especially caching), some things in C++ actually can be faster just because the compiler is better at optimizing for that.

            • jabjoe@feddit.uk
              link
              fedilink
              English
              arrow-up
              2
              ·
              8 months ago

              There is nothing you can do in C++ or C, that can’t be done in the other. It’s the kind of the point of those languages.

              • refalo@programming.dev
                link
                fedilink
                arrow-up
                2
                ·
                8 months ago

                Technically you’re right, but I don’t think that changes what I said about optimization. There are still cases where equivalent C++ code can be faster than the C version merely due to different optimizations used.

                • jabjoe@feddit.uk
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  8 months ago

                  Meh, I’m unconvinced. If it’s any kind of hot spot, in either, you can optimize the hell out of it. C++ is often more bloated is it’s just a harder language pretending to be an easier one.

                  • refalo@programming.dev
                    link
                    fedilink
                    arrow-up
                    1
                    ·
                    edit-2
                    8 months ago

                    That’s fine, you don’t have to agree. Personally I do like to use just a few features of C++ without going too crazy, like simple classes and maybe one level of inheritance, but I don’t really get into templates or exceptions or other really complex/controversial stuff. I prefer having the stronger typing and better readability of this kind of C++, and I think it helps me make less mistakes, but I realize not everyone agrees, and that’s ok.

    • expr@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      8 months ago

      Yeah it’s pretty great, especially when so many people are so quick to assume that OOP is essential for managing complexity.

      OOP is the poster child for solving the problems that it creates itself.