Those weird humans
Tags: oop, functional, story, wrongelves
Published: 2021-11-23 21:11:19

A bunch of young elves sit in silence by the fireplace of a wooden cabin in the north pole.

Eventually a tiny elf called Galadriel breaks the silence, "Grandpapa, can you tell us a story?"

"Sure thing, kiddo!" responds an elderly man with a long white beard, "I'll make myself a hot cocoa and be right there with you."

The old man approaches a cast-iron stove upon which sits a kettle and a pot of milk. A few minutes later, cocoa in hand, the old man sits in a rocking chair by the fireplace and asks the elves "Which story would you like to hear?"

"I know! I know!" says another tiny elf called Legolas, "tell us a story about..."

## Those weird humans

"Ho ho, where do I even start!" the old man laughs, "I know, I'll tell you a story of good intentions, people getting carried away, broken toys and forgetfulness."

"Wow that sounds amazing!" young Galadriel shouts excitedly.

"The story begins not long ago, in this galaxy" the old man says while pulling the cowl of his robe over his head, "Humans used to worship this _thing_ called OOP."

"_Up?_" asks Legolas.

"No no, OOP" the old man responds.

"Whoop?" Legolas tries again.

"Ho ho, that's certainly closer, but no, this is O-O-P which stands for Object-Oriented Programming."

The elves stare in awe until Arwen says "tell us more about..."

## Oh-Oh Pee

Outside it's snowing, but this is not the usual snow. For some magical reason, around this cabin it snows all the time and yet the height of the snow is always exactly right. Ideal for building snow people and friendly snowball matches, but never high enough that you need to spend hours shoveling your backyard and over-seasoning your driveway with a ton of salt.

"Back then" the old man continues, "humans decided that objects in the real world only had two properties: _state_ and _behavior_."

"Behavior was good, everyone wanted _behavior_, but state, oh no, state was something to be ashamed of, something to be _hidden_."

## Something hidden

"They invented this thing called _encapsulation_ that meant that objects would hide their state so that no one could know about it."

"Those were strange times indeed, the sole purpose of objects was to _do_ stuff, not just sit around. There was not time for quiet contemplation back then."

"Eventually they started grouping objects together, [solid](https://en.wikipedia.org/wiki/SOLID) objects and animals were very popular back then, although humans were obsessed with making all of them [bark()](https://dev.to/acroynon/inheritance-and-polymorphism-33fi) for some reason."

## Going too far

"Humans are excitable creatures. They have a saying that goes pretty much like this: when you have a new hammer everything looks like a nail."

"And, so they started seeing objects everywhere. Animals, People, Cars, those kind of made sense, but eventually they got carried away. Numbers, functions and even abstracts like [dignity](https://i.ytimg.com/vi/Uw3AghZHCdk/maxresdefault.jpg) became objects."

"Back then the only way to accomplish anything was to pass objects around, but given that objects had all those enticing methods you could call, it took an enormous amount of restrain to write [pure functions](https://en.wikipedia.org/wiki/Pure_function)."

"It's like when you kids share your toys. They eventually break and when they do, it's hard to tell who broke it, where did it break and where are all of its pieces so that you can try to put it back together."

"Last week I shared my wooden car with Legolas and he broke it!" complains a little elf called Elrond.

"I did not!" says Legolas.

"You did so!"

"I did not!"

This goes on for a while until the old man continues the story, "...so apparently all those broken toys and impure functions had an unprecedented effect on the world, they triggered a..."

## World-wide iron deficiency

"It turns out that most objects in the world were suffering from an iron deficiency that turned them into [anemic objects](https://martinfowler.com/bliki/AnemicDomainModel.html), leaking state all over the place."

"Those were dire times to be an object, and almost everything was one."

"At some point humans got fed up with objects, leaking or otherwise and decided everything about OOP was wrong. They concluded that OOP really stands for Outrageously Overly-complicated Programs and moved on without a second thought."

"...aaaand that concludes our story for today!"

"But if they no longer used objects, did the have another way of solving problems?" little Elrond asks.

"Yes, lots" answers the old man, "like functional, logical, procedural, JavaScript..."

"Grandpapa" Galadriel moans with the most heart-warming sad-kitten face, "could we have one more story before bed time, please? Pretty please?"

"Alright, kiddo, but this is the last one!"

## An older, newer story

"Before humans started worshiping OOP (or was it after?) they were obsessed with something called FP."

"What is it with humans and all this _pee_?" asks Legolas.

"Ho ho ho, FP stands for Functional Programming and it was quite different from OOP."

"Grandpapa" Galadriel says, "please tell us more about..."

### Eph pee

"Well" the old man continues, "these humans got radically different views about state and behavior."

"For them state was something to put on display, where anyone could see it, but there was a catch, no one was allowed to touch it or otherwise _change_ it."

"They called this rule _immutability_."

"Wooo" all the elves say in unison, with amazement in their eyes.

"Now the key to FP was functions, but not just functions [_pure_ functions](https://en.wikipedia.org/wiki/Pure_function)."

"Remember that because of immutability you were not allowed to change things, so to get things done you'd use pure functions that take state and produce new things."

"But" Arwen interrupts, "how could you possible _do_ stuff when you're not allowed to _change_ stuff?"

"Ho ho ho, great question!" excitedly replies the old man.

### The unexpected

"It turns out that humans also asked the same question, how can we actually _do_ stuff if we cannot _change_ stuff?"

"They tried really hard to come up with an answer to this question, tried different approaches but nothing seemed to work."

"They were getting desperate, they were prepared to sacrifice anything in the altar of purity and immutability but this problem seemed impossible to solve."

"And so, they did the unexpected, something no one could've foreseen..."

"What was it Granddaddy??? What was _it_?!" all the elves ask excitedly.

"They..."

### Turned to the occult

"They realized that the only way to solve their predicament was by tapping into raw magic, into the most occult and forbidden of sciences: Math."

"They tried casting all sorts of math spells until one day, after a lot of effort and casualties, they managed to conjure an artifact of ultimate power."

"This artifact, forged in the fires of [Category Theory](https://youtu.be/I8LbkfSSR58) was called the Monad!"

"Now Category Theory is a bucolic valley right next to the wine country region of Hell. If you're ever in the area make sure you stop and visit."

"But I digress back to the Monad..."

## Shoulda, woulda, coulda

"These humans immediately became obsessed with these monads. [Maybe](https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-Maybe.html) it was that monads look deceptively simple. It was [either](https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-Either.html) that or that they felt [just](https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-Maybe.html#v:Just) [right](https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-Either.html#v:Right)."

"Whatever the reason, monads were too powerful an artifact to wield. They had the power to alter the fabric of reality and _change_ the immutable, make _state_ appear out of nowhere and to _run_ code that couldn't run."

"One of the most powerful monads out there was called [IO](https://hackage.haskell.org/package/base-4.16.0.0/docs/System-IO.html#t:IO)."

"Hey ho?" asks Legolas.

"I'm pretty sure that's the [punk rock](https://youtu.be/268C3N2dDYk) monad of [dwarves](https://youtu.be/HI0x0KYChq4?t=78)" the old man explains, "this one was called _eye oh_ which stands for Input-Output."

## Hasta la vista, FP / I'll be back

"Anyway, every monad on it's own was an artifact of untamed raw power and to be able to combine them required impossible amounts of [transformation magic](http://book.realworldhaskell.org/read/monad-transformers.html). But even then being able to [lift](https://hackage.haskell.org/package/transformers-0.5.5.0/docs/Control-Monad-Trans-Class.html#v:lift) all those monads required an almost superhuman strength."

"Eventually those humans realized they were getting ripped with all that heavy lifting so most of them decided to pursue a more satisfying career as Olympic heavy-weight champions, body builders, Hollywood superstars, pop-culture icons, restaurateurs and some even decided to dabble in politics."

"And so, once more humans forgot about FP and moved on to the next new shiny old thing."

"I sometimes think that being human is about trying to find balance by moving exclusively between the extremes."

"And that is the end of that story."

## Lots of jumping around

"Granddaddy" asks Arwen, "was there something before Eph Pee and Oh-Oh Pee? Maybe some other _pee_?"

"In the very beginning things were _very_ strange, people would spend all their time randomly [moving](https://c9x.me/x86/html/file_module_x86_id_176.html) things around and [jumping](https://en.wikipedia.org/wiki/JMP_(x86_instruction)) from here to there for no discernible reason."

"But this story will have to wait, kiddos, now it's time for bed, tomorrow we have a big day ahead of us. Lots of toys to compile, assemble, link and debug."

And so the little elves go to bed and the old man walks out to his bedroom.

## E-pee-log

A couple of minutes later, the old man emerges from his room in his robe and slippers and looks at you, yes, _you_ the reader.

"You're still here?" he asks shocked, "it's over, go home!"

Seeing that you are not leaving he continues.

"Oh, well, since you're still here, let me just say: you keep coding, code in whatever language and paradigm makes you happy and gets you excited."

"Don't worry about what people think or the hype, there's a lot of satisfaction to be had in punching holes in [Fortran cardboard cards](https://en.wikipedia.org/wiki/Computer_programming_in_the_punched_card_era#/media/File:FortranCardPROJ039.agr.jpg)."

"Learn about other ways of doing things, the crazier the better, then share what you've learned with others!"

"That's it, it's truly over now, go home, go share a (virtual or real) meal with friends and family."

"And, if you happen to find yourself at home, alone, then order pizza, watch a movie and use your toys to build traps and ward off some wet bandits."

"Happy holidays!"