I love memes.
They have this incredible ability to condense not just a message, but also culture, social context –and even– historical context.
They're powerful.
Picking the right meme is an art, and it depends even on the timing of the message; that's why this message must use the «Man Taking a Stand» meme (formally known as the Freedom of Speech meme)
Man Taking a Stand Meme declaring 'Hierarchy was a mistake'.
I picked this particular meme because class hierarchy is so deeply inception into programmers' minds that I feel this need to stand up.
My perception is that every programmer -whether formally educated or self-taught– has inherited (🥁🥁💥) this artificial need for:
class Dog extends Animal {}
I loathe you, fake, unrealistic, forced, unnatural, fabricated, yet harmful
Dog
class.
In Inception ( originally Paprika ) they explain how powerful an idea is.
the Dog
class represents this idea that "formal programming uses hierarchy because it leads to simpler and easier-to-understand code".
No, it does not.
Use composition It's Easier to understand
Beside textbooks, no one is using a Dog
class in the real world. Let’s look at a more realistic example, taken out of context, from an actual library:
class ExclusionBlend extends BlendModeFilter {}
class BlendModeFilter extends Filter {}
class Filter extends Shader
class Shader extends EventEmitter {}
abstract class EventEmitter {}
Now, I’m not sure how our minds work exactly, but there’s a limit to how much we can process and retain.
-> The number of logical structures we can keep in our short-term memory (like a mind-cache) is finite.
So, at some point, we forget:
"Where was the rendered
property declared?" "Was it in the Filter
class, or was it at the Shader
level?"
"Is the compileShaderFilter()
overriden for every Filter
, or do I need to use some specific property of my particular Blend
subclass?".
This is how i picture this: In abstract terms, the amount of this "short-term memory space" needed to visualize a class hierarchy is bigger than it should be, leading to conceptual overlaps and mental overhead.
Every item we add to the chain, we sum accumulated complexity to the mental model.
What about Composition? Won’t it require the same 'short-term memory' thing you mentioned?
🤔
No, I don’t think so.
Now –I’m going anthropology here– I think this relates to how real-life society works.
We live in a system modeled by composition, not hierarchy.
Sure, there’s a subtle hierarchy in life, like in DNA, but how does the day-to-day work?
-> My immediate world works through composition.
The other day at work, I needed to fill out some paperwork for HR.
I sent the request via email and received the procedure.
That request involved a different department than the one handling invoices.
So they forwarded my request to another department, where a different/specialized employee handled the details, solved the task, and sent the solution back to the operator who initially contacted me.
Every item we add to the chain does not accumulate complexity.
Later, I grabbed a coffee. There were two different baristas—one took my order, and the other prepared the drink.
What I didn’t encounter was some kind of Barista-Gestalt-Hive-Mind, an all-knowing employee where every barista "plugs in" each morning and inherits (🥁🥁💥) the ability to.....
The Barista-Gestalt-Hive-Mind 8-bit generated by Grok
You may find this metaphor ridiculous.
It is.
I’m trying to inception the idea that the human world runs on composition.
While hierarchy demands more mental space, a system built on composition requires less.
*Our minds naturally create "black box systems" in daily life.
We don’t need to know how every part works, just what it returns.
*
This is what makes it easier to keep all the pieces in our short-term memory. Our minds are perfectly fine with isolating components and simply expecting results—just like when we order a coffee.
Systems based on composition are also easier to unit test, but this is one of the longer articles I've published, and I like to keep this one abstract.
I WILL post a follow-up using pure JavaScript, pure Node, and/or pure React, defending the superiority of composition.
Stay tuned 📻
--
thanks for reading 💛
Interesting post, looking forward to how you approach the argument from a unit testing perspective!