• parlaptie@feddit.de
      link
      fedilink
      arrow-up
      10
      ·
      3 months ago

      There’s the camp of those who say that inheritance is synonymous with OOP. I’m not in that camp, but I’d like to see you duke it out with them.

      • HereIAm@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        3 months ago

        You will still have private/public sections, interfaces (unless you class them as inheritance), classes and instances, the SOLID principles, composition over inheritance. OOP is a lot more than just large family trees of inheritance, a way of thinking that’s been moved away from for a long time.

    • Blemgo@lemmy.world
      link
      fedilink
      arrow-up
      42
      ·
      3 months ago

      I think the main problem is that people try to shoehorn OOP mechanics into everything, leading to code that is hard to understand. Not to mention that this is basically encouraged by companies as well, to look “futuristic”. A great example of this approach going horribly wrong is FizzBuzz Enterprise Edition.

      OOP can be great to abstract complex concepts into a more human readable format, especially when it comes to states. But overall it should be used rarely, as it creates a giant code overhead, and only as far as actually needed.

      • seth@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        3 months ago

        I got as far as seeing they chose Java and opening the constants file, and immediately executed a strategic withdrawal. I love that people went to this level of detail

      • RandomException@sopuli.xyz
        link
        fedilink
        arrow-up
        6
        ·
        3 months ago

        Oh no, the FizzBuzz EE has evolved since I’ve last viewed it! 😱 Is it bad if it actually reminds me of my current work project’s backend (that I haven’t written) a bit?

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      13
      ·
      3 months ago

      People (sometimes) use it far too much and in wrong ways.

      Like inherit when you could just instantiate, or use a template.

      Or when “everything should be a class” was also a bummer (inhetit “run()”), like I’d instantiate “main” twice (cool if it had worked I guess).

      Or old code written by “wizards” where they cast cast cast instances onto other classes to use specific behaviour in crazily dangerous manners. And you’re the one to “fix it” because it doesn’t work well…

      Otherwise OOP is good.

      • zalgotext@sh.itjust.works
        link
        fedilink
        arrow-up
        14
        ·
        3 months ago

        Just like any software design principle, it’s understood at a surface level by tons of bad developers who then try and solve every problem with that one principle. Then slightly better developers come along and say “ugh this is gross, OOP is bad!” And then they avoid the principle at all costs and tell everyone how bad it is at every opportunity.

    • PeriodicallyPedantic@lemmy.ca
      link
      fedilink
      arrow-up
      13
      arrow-down
      2
      ·
      3 months ago

      There are common traps and employer don’t spend money/time to train their devs to avoid them.

      SOLID principles are pretty decent but a surprising number of people don’t do any of them

    • HStone32@lemmy.world
      link
      fedilink
      arrow-up
      4
      arrow-down
      3
      ·
      3 months ago

      If you ask me, the only reason for objects to exist are for preventing stale references. Anything more than this is unnecessary.

  • MajorHavoc@programming.dev
    link
    fedilink
    arrow-up
    54
    arrow-down
    6
    ·
    3 months ago

    Interfaces are great.

    Inheritance is often a sign that the previous developer didn’t understand interfaces.

      • MajorHavoc@programming.dev
        link
        fedilink
        arrow-up
        26
        arrow-down
        2
        ·
        3 months ago

        Yep. I’m old, cranky, and prone to broad statements to get reactions.

        That said, for any of you all that love inheritance, I’m judging you so hard. So hard. Very judged. I probably hate your code, and your friends’ code, and your last teacher’s code. Especially your last teacher’s code.

  • Artyom@lemm.ee
    link
    fedilink
    arrow-up
    13
    ·
    3 months ago

    Inheritance makes complicated objects that would otherwise be impossible possible, but it only works if you know those objects really well. The problem is people write ridiculously complicated mystery objects in libraries and no one knows what’s going on anymore.

    • lseif@sopuli.xyz
      link
      fedilink
      arrow-up
      3
      ·
      3 months ago

      that, and that its often not the best use of time to map out the entire project structure in uml before u even write a method…

    • platypus_plumba@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      3 months ago

      Springboot is very confusing. The inheritance tree is insane, they created a class for everything, which I get… But it is so hard to understand the whole scope their design.

    • Gonzako@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      3 months ago

      Tho, C# is statically typed so you can look at the available methods any one library has at any time in the IDE

      • herrvogel@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        3 months ago

        Excuse me if I don’t appreciate when the compiler adamantly refuses to do its job when there’s one single unused variable in the code, when it could simply ignore that variable and warn me instead.

        I also don’t enjoy having to format datetime using what’s probably the most reinventing-the-wheel-y and most weirdly US-centric formatting schemes I have ever seen any programming language build into itself.

  • Caveman@lemmy.world
    link
    fedilink
    arrow-up
    16
    arrow-down
    6
    ·
    3 months ago

    Using classes is nice tbh. Using inheritance usually isn’t. Inheriting from inherited class should be forbidden.

    • lseif@sopuli.xyz
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

      Inheriting from inherited class should be forbidden.

      so an interface with state?

      • Caveman@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        Those are nice. Services that manage data are an example. Having the class also declare how to interact with the data is nice.

        My most OOP pattern I like using is implementing an interface with an abstract class for “standard” implementation. Then implement abstract methods for a concrete thing.

  • HStone32@lemmy.world
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    3 months ago

    I used to think I was just a fanboy. But as time went on and I gained more and more experiences, I’ve only become all the more sure that ANSI C is the only language I ever want to write anything in.

    • Jears@social.jears.at
      link
      fedilink
      arrow-up
      6
      ·
      3 months ago

      I was the same, but I recently gave zig a try, it’s lovely to write.

      Managed to segfault the compiler though, so maybe not quite ready yet.

  • JoYo@lemmy.ml
    link
    fedilink
    English
    arrow-up
    4
    ·
    3 months ago

    C++ classes are fairly optional but if you’re already using cpp then it likely wasn’t your choice and neither will the choice of OOP.

    • Buddahriffic@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      3 months ago

      Yeah, I like the sweet spot that C++ is in. It can do anything C can but then you have classes and STL and all that on top of it.

      • JoYo@lemmy.ml
        link
        fedilink
        English
        arrow-up
        2
        ·
        3 months ago

        once i learned about defer it became a hard requirement. cpp kinda gives me that but other c like languages do it better.

        • Buddahriffic@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          3 months ago

          Yeah, I wish C++ had function/scope epilogs and labeled loops/breaks, too. Those are the cases where the “never use goto” rule can be broken to make better code than adding all of the code that would be required to handle it the “right” way (setting up early exit flags and if statements after each level of nested loop to check the flag).