If you're composing a class out of multiple chunks of functionality then all of the bits you want to call need to be public. If you're sublcassing and overriding then the bits you're overriding can be internal, and not part of your public API.
If Inheritance is so bad, why does everyone use it?
61–70 of 389 posts
Re: If Inheritance is so bad, why does everyone use it?
#62Re: If Inheritance is so bad, why does everyone use it?
#63I don't think inheritance is bad at all. It is very often the easiest way by far to model a problem. Sure, it's not perfect, but I think it is wildly overhated by a vocal minority.
Have you ever seen wildly over-architected OO code where everything seems to be an abstract class and it seems impossible to find out where stuff actually happens? Inheritance is like a lot specialised tools - it can be useful in some situations but I think those are rarer than supporters might thing. Completely refusing to use inheritance and always using inheritance both seem like extreme views that should be avoid…
I guess one could say this would be workable with proper tools, but the IDEs just aren't there. Move up a level in inheritance, ctrl-click on a call? It was overriden somewhere in the hierarchy, but the IDE will send you to the parent-class definition regardless.
Re: If Inheritance is so bad, why does everyone use it?
#64Earlier quoted context omitted.
Pragmatists used inheritance because it gave a quick benefit now, and the longer-term costs were ignored. Some pragmatists became successful because they moved quickly, so the "Programmers from the Church of Purity" used inheritance because successful companies used inheritance. When inheritance was no longer the quickest way to move quickly, the pragmatists moved on. The Church of Purity now bangs on about Functiona…
> Pragmatists used inheritance Because at some point mainstream OO languages made inheritance easy and composition harder, nothing more. Composition with Java used to be verbose. Inheritance declaration was simply a single keyword. If Java had "mixins" from the start, people would have used composition way more.
Re: If Inheritance is so bad, why does everyone use it?
#65The zoo animal metaphor that you often see used in teaching inheritance (lions are animals, simba is a lion all animals have a length, but lions also have claws etc.) is a bad perspective and you should never use inheritance to model a problem like that in the real world.
The only time I’ve used inheritance, has been on toy problems that didn’t need it. Not to say it doesn’t have its place but when I encounter it, it’s time consuming to peel back all the layers or deal with idioms that don’t quite fit a problem that a developer has enforced through inheritance.
Re: If Inheritance is so bad, why does everyone use it?
#66My impression is the opposite, especially from when I used to work as a full-time Java dev. I often asked myself: Is there a place outside of GUI programming where inheritance is used in non-habitual and useful way? I can't think of many. More often than not you have a final class that you are supposed to use and the petrified hierarchy above that is of not much use.
Re: If Inheritance is so bad, why does everyone use it?
#67Earlier quoted context omitted.
What specifically slows it down in your context?
Doing every simple thing that used to be done in "normal procedural" way in functional paradigm instead when using something like Scala or fp-ts in TypeScript. Causing engineers to completely change their mental model of how the code runs, which I still have intuitive trouble imagining correctly and I see it with other developers as well. A lot of energy goes into trying to understand how to do a simple action. It is…
Re: If Inheritance is so bad, why does everyone use it?
#68Earlier quoted context omitted.
Doing every simple thing that used to be done in "normal procedural" way in functional paradigm instead when using something like Scala or fp-ts in TypeScript. Causing engineers to completely change their mental model of how the code runs, which I still have intuitive trouble imagining correctly and I see it with other developers as well. A lot of energy goes into trying to understand how to do a simple action. It is…
Would you say it's a retraining cost, or would you imagine still having this issue many years from now, assuming you keep working on it?
I feel like I spend more time and energy on how to get something done functionally rather than focusing on what the correct business logic should be.
Re: If Inheritance is so bad, why does everyone use it?
#69I 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…
Re: If Inheritance is so bad, why does everyone use it?
#70I 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…