top | item 31865771

(no title)

redisman | 3 years ago

I disagree. Teaching people to think about abstractions wrong is not in any way helpful. Everyone I know including myself had to spend years writing bad code before realizing that this way of thinking is counterproductive. It reminds me of this quote from Kung Pow

Don’t worry about Wimp Lo, he’s an idiot. We’ve purposefully taught him wrong… as a joke.

Composition is an infinitely better method to teach if you have to teach OOP. That way you don’t need to unlearn what you thought was the right way but is actually useless at modeling almost anything.

discuss

order

moron4hire|3 years ago

I'm so sick of this "composition is so much better than inheritance" talking point that seems to have become dogma in the last 5 years. You use both. They are completely different things.

Look at a classically inheritance-based system: a GUI library. You'll see lots of inheritance. Buttons and Checkboxes extend ClickableThing, ClickableThing extends Control. Whatever.

And then you compose those controls on a Form.

Look at a classically composition-based system: a video game entity-component system. You'll see Monsters composed of GraphicsObjects and Animations and WeaponSlots and AIAgents.

And you implement all of those components in an inheritance hierarchy, or else your GameObjectThinger can't have a list of them that can grow or shrink at runtime.

So keep saying "teach composition, not inheritance". You might as well tell musicians to study "rhythm, not tempo".

sumy23|3 years ago

Those are good examples of inheritance. However, I think they'd be better served with mixins, which is another form of composition.

JoshCole|3 years ago

Abstractions are useful because they simplify and if you don't allow error you don't allow maximization of simplification. You can formally relate this to learning problem formulation complexity. When you do you encounter things like branching factors which effect solution times which lead to natural results like fast but finishes being better than optimal but never terminates. This can hold even despite error in the abstraction and there are techniques for recovering that error at runtime because a particular problem is a less general and more specific situation and so isn't as cursed by branching factor.

Edit: A previous version of this comment was more wordy in stating this and mentioned that there are formal proofs to this effect.

random314|3 years ago

I don't think this constitutes a formal proof on any way at all.