• velox_vulnus
    link
    fedilink
    English
    01 month ago

    GOOPs and CLOS exists in functional programming languages. Just saying.

        • @Armand1@lemmy.world
          link
          fedilink
          01 month 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
            link
            fedilink
            English
            01 month 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.

              • Ethan
                link
                fedilink
                English
                01 month ago

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

      • @el_abuelo@lemmy.ml
        link
        fedilink
        01 month 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
          01 month 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
            01 month 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.

  • @kibiz0r@midwest.social
    link
    fedilink
    English
    01 month ago

    The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said “Master, I have heard that objects are a very good thing - is this true?” Qc Na looked pityingly at his student and replied, “Foolish pupil - objects are merely a poor man’s closures.”

    Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire “Lambda: The Ultimate…” series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.

    On his next walk with Qc Na, Anton attempted to impress his master by saying “Master, I have diligently studied the matter, and now understand that objects are truly a poor man’s closures.” Qc Na responded by hitting Anton with his stick, saying “When will you learn? Closures are a poor man’s object.” At that moment, Anton became enlightened.

    • @Valmond@lemmy.world
      link
      fedilink
      01 month 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.

    • @HStone32@lemmy.world
      link
      fedilink
      01 month ago

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

    • @Blemgo@lemmy.world
      link
      fedilink
      01 month 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
        01 month 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

  • @HStone32@lemmy.world
    link
    fedilink
    01 month 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.

  • JoYo
    link
    fedilink
    English
    01 month 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
      01 month 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
        link
        fedilink
        English
        01 month 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
          01 month 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).

  • @olafurp@lemmy.world
    link
    fedilink
    01 month ago

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

      • @herrvogel@lemmy.world
        link
        fedilink
        01 month 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.