News for hackers. Stuff that matters.
Re:If Inheritance is so bad, why does everyone use it? by v1sea on Thursday April 11, 2024 @03:59AM (#39999522)
The 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 > 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

[1] https://wiki.vg/Entity_metadata#Donkey

[2] https://wiki.vg/Entity_metadata#Blaze

Re:If Inheritance is so bad, why does everyone use it? by Sakos on Thursday April 11, 2024 @04:05AM (#39999571)
Both of those look like perfect cases for composition instead of inheritance.
Re:If Inheritance is so bad, why does everyone use it? by coffeebeqn on Thursday April 11, 2024 @02:29PM (#40005268)
Anyone not using components for game objects is insane. How do you add a fire breathing horse without that
Re:If Inheritance is so bad, why does everyone use it? by feoren on Thursday April 11, 2024 @05:30PM (#40007034)
Yes, now take it further. Anyone not using components for all domain modeling is insane. Why does everyone assume this wonderful practice only applies to games?
Re:If Inheritance is so bad, why does everyone use it? by Asraelite on Friday April 12, 2024 @05:26AM (#40010813)
Because the negative consequences are more pronounced in games. You can more easily get away with not doing it in other domains, so there it may be silly, but not "insane".
Re:If Inheritance is so bad, why does everyone use it? by maeil on Wednesday April 17, 2024 @01:30AM (#40060810)
Any recommendations for where we can learn about this approach, or recommended search terms? I'm struggling to find anything through Google that isn't about the Unity component system in specific. Is it this? [1]

https://en.wikipedia.org/wiki/Entity_component_system

Re:If Inheritance is so bad, why does everyone use it? by v1sea on Saturday April 20, 2024 @04:56PM (#40100945)
Yeah, that is it. I found this book to be pretty good https://gameprogrammingpatterns.com/ and heard good things about https://www.gameenginebook.com/
Re:If Inheritance is so bad, why does everyone use it? by monknomo on Thursday April 11, 2024 @05:10PM (#40006844)
why is monster vs ageable mob a good cleavage? This is odd
Re:If Inheritance is so bad, why does everyone use it? by TheBigSalad on Friday April 12, 2024 @01:50PM (#40015638)
Jesus, that's insane! The rule of inheritance is no more than 3 levels deep. 3!!