• Jim@programming.dev
    link
    fedilink
    English
    arrow-up
    13
    ·
    1 year ago

    Most of us have bad memories of over-complex hierarchies we regret seeing, but this is probably due to the dominance of OOP in recent decades.

    This sentence here is why inheritance gets a bad reputation, rightly or wrongly. Inheritance sounds intuitive when you’re inheriting Vehicle in your Bicycle class, but it falls apart when dealing with more abstract ideas. Thus, it’s not immediately clear when and why you should use inheritance, and it soon becomes a tangled mess.

    Thus, OO programs can easily fall into a trap of organizing code into false hierarchies. And those hierarchies may not make sense from developer to developer who is reading the code.

    I’m not a fan of OO programming, but I do think it can occasionally be a useful tool.

    • Spott@lemmy.world
      link
      fedilink
      English
      arrow-up
      6
      ·
      1 year ago

      I think part of the problem isn’t just bad hierarchies, it is that they are so hard to fix.

      Bad OOP code gets its fingers everywhere, and tearing out a bad hierarchy can be downright impossible.

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

        Yeah that’s a good point. It’s telling that inheritance is by design difficult to change unless you follow very specific rules of good OO design patterns.

        I guess it’s easy to write bad code in any programming paradkgm but inheritance makes it easy to screw up.

    • nous@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      1 year ago

      Lots of people equate OOP with inheritance, and I think that does a disservice to OOP code style in general. The original definitions of OOP had nothing to do with inheritance at all and this relationship was only popularized by a few languages (which others then copied due to aggressive marketing).

      IMO the more important parts of OOP that are still useful are encapsulation and message passing which can be done in languages without inheritance.

      I would caution against throwing out a paradigm before of one aspect of of that languages added onto it after the fact.