Live data from Hacker News

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

buttondown.email

121–130 of 389 posts

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

#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

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

#122
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 code in ten years, etc etc. Java correlates with, but does not cause, those conditions.

Another way of saying it: if Java was good enough for Nutch to use to write Minecraft, it's good enough for the vast majority of business purposes.

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

#123
post #80

It seems like protocols solve 90% of the problems that inheritance does, but with 10% of the headaches. Instead of trying to ensure that two types can both be passed to a function that only knows about the parent type, just have a parameter that says "Whatever's passed has to conform to this, I don't care what it is otherwise."

Code example?

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

#124

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…

Obligatory: Tailwind

Explain?

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

#125

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…

>For me the main point is (runtime) polymorphism.

But you don't actually care about runtime polymorphism here. You care about polymorphic behavior, which can be implemented in a much more composable way with parametric polymorphism.

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

#126

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…

if i were writing an intro to programming book, i would introduce OO as a means of building encapsulation. i'd only get into inheritance in later chapters.

You can have encapsulation without oop. Polymorphism is the real benefit of oop imho

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

#128
post #54

Inheritance is a local maxima. When the hierarchy of classes to consider is small, it often “seems to fit”. It allows the programmer to progress quickly and with low effort as a lot of the code sharing behavior is provided by the inheritance mechanism. Trouble often comes down the line. We keep adding classes, and soon we find that the hierarchy no longer is “shaped like a tree”. A soccer ball is a spherical object b…

That’s true of all knowledge organizational structures though. Even with composition, you end up with hierarchies that later you might turn on their heads, and also, those structures might end up being cyclical.

Paradigm shifts happen and shake up even loosely organized into structures like human perception, and most people’s perceptions aren’t trees

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

#129

Earlier quoted context omitted.

Inheritance doesn't work well for games, that's why so many games take a component based approach like Unity, or full blown ECS.

Well, it does work well for the engine part of game engines, and graphics related code in particular as the GP says - it's just gameplay code where OO falls a bit flat.

Unless it'a role playing game.

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

#130

I think it is pretty clear that the reason inheritance is so prevalent is because it is a superficially good sounding idea, which again and again is being put in front of people. I am sure that many, many people have had the experience of a professor tell them a nice sounding story about purely hierarchical data and went on thinking that this is the way data should be modeled. Thankfully I believe that nowadays many…

I don't know about other colleges, but when I teach my students inheritance, I tell them right away that it's a pretty bad idea. And that they will learn better ways in the next semester.
Post reply on HN