Do they? I rarely see people using it directly and I think this is fine
If Inheritance is so bad, why does everyone use it?
31–40 of 389 posts
Re: If Inheritance is so bad, why does everyone use it?
#32Here is my take on it. At one point "Object Oriented" became "Blockchain" (or now Gen AI) of those times. You had to be "object oriented" in order to be taken seriously. This applied to everything. Even finished software products were called "built using object oriented". The esoteric concept of inheritance became popular after that. At some point it became so popular that people figured out that it is not really a g…
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…
Re: If Inheritance is so bad, why does everyone use it?
#33The worst example of inheritance I've ever found is in java Minecraft's mobs[0]. It is very deep in some places and has numerous examples of sub classes not fully implementing their parent interfaces.
Example 1: Donkey[1]
Donkey > Chested_Horse > Abstract Horse > Animal > Ageable Mob > Pathfinder Mob > Mob > Living Entity > Entity
Example 2: Blaze[2]
Blaze has a bit for 'Is on fire', but how is this any different from Mob 'Is aggressive'? Blaze > Monster > Pathfinder Mob > Mob > Living Entity > Entity
[0] https://wiki.vg/Entity_metadata#Entity
Re: If Inheritance is so bad, why does everyone use it?
#34Re: If Inheritance is so bad, why does everyone use it?
#35Sometimes inheritance is extremely useful. Sometimes it's harmful. Sometimes it's not the best but the most practical nontheless.
Language concepts are tools. These people with extreme black and white views live under the delusion that there can be some "Perfect Language which will cause the program to never develove/get technical debt TM".
Pure delusion.
Real life is an approximation where you do what is best in practice, not in some delusional daydream of perfection which breaks the moment you try and bring it to reality.
Re: If Inheritance is so bad, why does everyone use it?
#36IMHO inheritance works and only works for graphics related programming, e.g. GUI and games. Visual objects can be abstracted in the manner of inheritance.
Re: If Inheritance is so bad, why does everyone use it?
#37Kotlin has a few nice patterns here. It allows inheritance but only if you mark your class as open (it's closed by default). This prevents people inheriting from things that weren't designed from that. It also has extension functions, which allows you to add functions and properties to types without having to inherit from them. This is very nice for fixing things that come with Java libraries to be a bit more Kotlin…
Re: If Inheritance is so bad, why does everyone use it?
#38Re: If Inheritance is so bad, why does everyone use it?
#39For 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-else statements, you should put the code for the special cases in the classes, not in each function that operates on them.
You can get this without implementation inheritance, it is also possible to just have something like interfaces. But I do find it very convenient to put common code in a base class.
Re: If Inheritance is so bad, why does everyone use it?
#40The article has a nice history review of inheritance, but it would have been useful for there to be some concrete examples. The worst example of inheritance I've ever found is in java Minecraft's mobs[0]. It is very deep in some places and has numerous examples of sub classes not fully implementing their parent interfaces. Example 1: Donkey[1] Donkey > Chested_Horse > Abstract Horse > Animal > Ageable Mob > Pathfinde…