Live data from Hacker News

If Inheritance is so bad, why does everyone use it?

buttondown.email

131–140 of 389 posts

Re: If Inheritance is so bad, why does everyone use it?

#131

It seems like there's a huge industry of people critiquing Java and OOP but misdiagnosing the problems as technical rather than sociological. The immense pain and suffering that is related to Java and its ecosystem is because of the terrible organizational conditions that tend to co-occur with usage of Java. Big slow companies, long boring meetings, arguments about design patterns, "architects" who haven't written co…

Java complexity is also an artifact of Java being used in large complex systems. People are really complaining about how hard programming is. There are many types of large scale systems where I would only code it using the JVM, everything else is a nightmare. Big tech companies largely feel the same

Re: If Inheritance is so bad, why does everyone use it?

#132

Nobody calls it this, but cascading styles in CSS is just like inheritance and I think should be avoided for all the same reasons. I feel it's a big part of why CSS at scale becomes unmaintainable. There isn't even a built-in way to compose two classes together if you want to avoid cascading/inheritance. It looks like composition over inheritance has caught on as the better default in other languages, but in the CSS…

It’s not only inheritance, it’s also lack of encapsulation and of separation of concerns, which leads to attack vectors like: https://news.ycombinator.com/item?id=39928558

Re: If Inheritance is so bad, why does everyone use it?

#133

Oh, darling, strap in because the Hacker News catwalk is serving us a spicy mix of opinions on inheritance in programming! First up, we've got the crowd who treats CSS like it’s the ugly stepchild of inheritance, preaching the gospel of "composition over inheritance" as if it's the latest fashion trend. Then there's the old guard, clutching their pearls and insisting that inheritance isn't the problem—it's just misun…

It's funny how easy it is to spot a ChatGPT reply

Re: If Inheritance is so bad, why does everyone use it?

#134
post #15
post #3

IMHO inheritance works and only works for graphics related programming, e.g. GUI and games. Visual objects can be abstracted in the manner of inheritance.

That's strange because I was about to comment the exact opposite. ECS is for games, inheritance is for almost everything else

For games having your character as a type of a general class fits well. Having enemies be a type of a class with a base of abilities can fit well too. Weapons, etc all module well. Game play. Scenes.

Re: If Inheritance is so bad, why does everyone use it?

#135
post #121

I love the way people take their narrow range of experience and over generalize it to everything. Bonus points for having a blog or maybe a patreon to tell everyone how it really is. We have a million flavors of the month but in the end it doesn't really matter. Pick a flavor and there will be teams that are successful and teams that are not. No silver bullet will make the non-successful teams magically turn into suc…

Ha ha, yes, happens all the time. In this case, published in a book 30 years ago, at least: https://news.ycombinator.com/item?id=40005520

Ahhh good 'ol XP/Gang of 4. Never ceases to be referenced. (for good reason)

Re: If Inheritance is so bad, why does everyone use it?

#136
Boring answer: Same reason we do a lot of stupid things, haha.

“If C is so unsafe and C++ is so unwieldy why does anyone use them?”

Because that’s what they learned, or because that's how the codebase is structured when you get there. When all you have is a bike you’re going to ride that shit everywhere.

You rarely if ever get the chance to start from scratch at work (where most code is written) and your job is to follow the pre-set pattern most of the time unless it becomes completely untenable. Sure, inheritance is worse in pretty much every way, but if everyone you're hiring does it that way, your codebase is built that way, etc, you're going to make the best of it because that's your job.

Re: If Inheritance is so bad, why does everyone use it?

#137
It’s only implementation inheritance that is questionable, and the reason is that it leads to mutual dependencies on implementation details between superclass and subclass. Reasoning about correctness becomes difficult, and the superclass is very constrained in what implementation details it can change without potentially breaking some subclass.

Bertrand Meyer’s open-closed principle can be read that way: The superclass is closed to modifications. But that goes against the principle of decoupling interface from implementation: The superclass interface is now stuck with the existing superclass implementation.

Re: If Inheritance is so bad, why does everyone use it?

#138

I feel people don't understand what inheritance and (object orientation in general) is useful for, misuse it, and then it gets a bad reputation. It's not about making nice hierarchies of Cars, Fruits, and Ovals. For me the main point is (runtime) polymorphism. E.g. you have a function that takes a general type, and you can pass multiple specific types and it will do the right thing. And if you want to avoid huge if-e…

Unfortunately a lot of developers are conditioned so heavily to believe that inheritance is intrinsically bad, that they contort their code into an unreadable mess just to re-implement something that could have been trivial to do with inheritance.

I'm not saying that I like it everywhere; IMHO it's a tool to be used sparingly and not with deep hierarchies. But it's not reasonable to avoid it 100% of the time because we're soiling ourselves over the thought of possibly encountering the diamond problem.

Re: If Inheritance is so bad, why does everyone use it?

#139
When I learned programming as a teenager, I was using one of the C++ classics which, of course, taught OOP and Inheritance as a magic silver bullet.

When I then finished the book and its examples, I wanted to do my own exercises and went through about 1-2 very painful years trying to model my things using Inheritance and totally blamed myself for being too stupid to do software development.

Only then I started searching and finding essays and blog posts of people criticizing OOP and esp. Inheritance for exactly the things I was struggling with. This felt like a relief!

My question: Why is Inheritance still taught as a silver bullet? I'm seeing university courses using Inheritance both for Domain and infrastructural code reuse at the same time. Esp. in Germany I see a lot of stupid 90s alike "programming" courses and, no shit, according code bases. It's as if they were living in a gigantic bubble.

Re: If Inheritance is so bad, why does everyone use it?

#140
My situation is different than a lot of others--I work mostly with code-bases I 100% control--but I just don't use inheritance all that often, and if I do, it's never deeper than one or two levels. Now, I do most of my programming in Python and in JavaScript, and I do like using python's ABCs to specify interfaces for interfaces that I expect to be implemented, but that's mostly the end of it.
Post reply on HN