• JoYo@lemmy.ml
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year 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
      0
      ·
      1 year 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
        0
        ·
        1 year 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
          0
          ·
          1 year 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).

    • erp@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Inheritance starts to suck > 1 level deep. Multiple inheritance starts to suck at the point people discuss adding it to a language, or a few femtoseconds after the big bang, whichever comes first.

      • ThyTTY@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        It would say Prototype­Filter­Stub­Facade­Bridge­Decorator­Task­Request­Map­Event­Exporter­Info­Model­Request­Iterator

      • marcos@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        I’m just not sure what the middle guy would be saying

        “I hate inheritance! I hate inheritance! I hate inheritance! I hate inheritance!”

        But well, inheritance goes brrrrrr.

        • erp@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          We all get disappointed when we don’t inherit anything useful…just a garage full of confusion

    • azertyfun@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Anyone who praises FP is either a student, works primarily in academia, or otherwise never had to look at a deep stack trace in their life.

      Every time a production system spits out a backtrace that’s just 15 event loop calls into a random callback, I lose 6 months life expectancy. Then I go look at the source, and the “go to definition” of my LSP never works because WHY WOULD IT, IT’S ALL FUNCTIONAL hapi.register CALLS

      I hate it I hate it I hate it I hate it. I support UBI because the people pushing functional programming in real production systems should be reassigned to gardening duties.

      • Miaou@jlai.lu
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        I have the same problem with oop. 10 levels of encapsulated calls just to see you were in an overridden methods without enough data to find out which implementation it was. Ugh

        • azertyfun@sh.itjust.works
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          I mean, bad programming sucks regardless of the “paradigm” (and vice-versa, mostly). But as someone whose job it often is to sift through production logs hunting for an issue in someone else’s component, at least I have a chance with OOP, because its behavior is normally predictable at compile time. So with the source and the backtrace I can pretty reasonably map the code path, even if the spaghetti is 300 calls deep.

          Now where shit really hits the fan is OOP with dependency injection. Now I’m back to square 1 grepping through 15 libraries because my LSP has no idea where the member comes from. Ugh.

      • arxdat@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        I’m not advocating one way or the other, but I would gladly take on the gardening duties :D

      • herrvogel@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        1 year 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.

  • HStone32@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 year 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
      0
      ·
      1 year 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.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year 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
        0
        ·
        1 year 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.

    • HStone32@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

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

    • PeriodicallyPedantic@lemmy.ca
      link
      fedilink
      arrow-up
      0
      ·
      1 year 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

    • Blemgo@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year 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
        0
        ·
        1 year 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
        0
        ·
        1 year 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?

  • Caveman@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 year 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
      0
      ·
      1 year ago

      Inheriting from inherited class should be forbidden.

      so an interface with state?

  • anyhow2503@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    I haven’t used TypeScript in a classically OOP way and it never felt like I was being urged to do so either.

        • Armand1@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          Of course, but OOP is typically about putting methods on classes, inheritance of behaviour etc.

          JS Objects aren’t typically used that way, they tend to be used as pure data containers. At least, that’s how we mostly use them.

          Occasionally, we’ll use objects to simplify passing multiple arguments including arrow functions, but I’d say that doesn’t really count unless the arrow function mutates the object it’s a part of.

          • Ethan@programming.dev
            link
            fedilink
            English
            arrow-up
            0
            ·
            1 year ago

            Of course, but OOP is typically about putting methods on classes, inheritance of behaviour etc.

            You’re referring to one subtype of OOP. That may be what most people mean when they say OOP, but that doesn’t make it correct. Object-oriented programming is programming with objects, which does not require inheritance or classes.

            • Miaou@jlai.lu
              link
              fedilink
              arrow-up
              0
              ·
              1 year ago

              With such a broad definition you could call even Haskell an oop language

              • Ethan@programming.dev
                link
                fedilink
                English
                arrow-up
                0
                ·
                1 year ago

                So you’re arguing that “Object oriented” shouldn’t apply to languages that are oriented around objects?

      • el_abuelo@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        Huh? I’ve worked with TypeScript + React for the last 5yrs and the only time I see OOP is when someone’s done something wrong.

        Maybe you’re thinking of old react with class based components?

        • toastal@lemmy.ml
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          Proving that adding the class keyword to the ECMAScript spec was a mistake that leads folks down a path they should not travel 🙃

          • el_abuelo@lemmy.ml
            link
            fedilink
            arrow-up
            0
            ·
            1 year ago

            I completely agree. I taught JS/TS for 5yrs and I always emphasised that the ‘class’ keyword was just syntactic sugar for what was already available in prototype inheritance of JS.

      • MajorHavoc@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        1 year 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.