🤯 functional funsies is now impure.fun 🤯

The Objects You Know and Love 💟

⏱ 4.5 min |


#ApplesForLambda Campaign

iOS users, if you've been here before when some text was missing, I hope you give it another chance!

This journey begins in a surprisingly familiar place. When comparing Functional Programming to Object Oriented Programming, it’s tempting to take the shortcut functions vs. objects, and understandably ask: what’s wrong with objects?

Nothing’s wrong with objects!

Consider the following (decidedly informal) definition of an object:

That last point notwithstanding, this definition makes objects a pretty useful concept for programming.

Wait, so objects are good?

The problem with Object Oriented Programming has never been with objects so much as with the orientation part.

Objects are not inherently evil, but the above definition means objects are a truly terrible, horrible, no bueno, very bad basic building block for a programming paradigm. Why? Because basic building blocks are supposed to be the simplest composable element you can think of.

Now re-read that definition and ask yourself: does it read like a definition of a simplest composable element of anything?

Why does this matter? Because when you compose an architecture, you want to focus on the composition and forget about the constituent parts, and it’s object orientation — meaning the choice of making objects the basic building block, not objects themselves — that makes this impossible.

Speaking of architecture

Take bricks 🧱 for instance, they’re an excellent basic building block because when you conceptualize a wall you no longer care about the individual bricks, only the outside boundaries of the wall matter. Let’s say a wall is defined as follows:

Like objects, walls are useful too, but if we were to use walls instead of bricks as a basic building block for construction, we’d have to change the definition above:

What happens when you pick the wrong basic building block is that you end up having to make all of its features optional, which is bad because optional features have to be declared, either explicitly or by convention, and their presence or absence has to always be considered.

Objects are nothing like bricks

The object oriented paradigm makes it very hard to only consider the outside shape of any composition because you seldom can afford to forget about its constituent objects, namely, you need to keep track of:

Not only you have to consider the above for the classes that you use, but also for their parents and their parent’s parents, and so on. They are really terrible basic building blocks.

But I code without doing any of this!

You can afford to code without doing some of this, some of the time, using patterns and practices with fancy names such as Inversion of Control, but no amount of patterns will let you ever reach a place where you don’t have to do any of this all of the time.

Such patterns exist not because they’re good coding practices, but because they’re good OOP disaster mitigation techniques.

As you venture further away from OOP, these arcane vestigial practices will no longer clog your brain or your code, as you will find that much of what they offer you get for free just for using a better paradigm.

OOP is really exceptional

Everything you can’t avoid even with good practices can be seen as a mental & code tax, which you are paying, often unknowingly.

In this way OOP is like a bad itch that you no longer notice you’re scratching, except when you stop, because you get exceptions.


Exceptions are so frequent when building OOP solutions that they’re generally accepted as necessary inconveniences towards a solution that’s eventually stable enough to focus on actual functionality.

This is sad because there’s an entire world out there where this silly workflow sounds like a terrible joke.

When you let go of objects as the basic building block of your code, exceptions become more and more exceptional, until one day you’ll be rewarded with a brand new solution created from scratch that just works,

Your first basic spell ✨

It may come as a surprise but a lot of the wizardry ahead doesn’t involve any maths or other scarier “m” words, and definitely none of that impenetrable category theory.

All it takes is using a simpler basic building block for your code which we’ll to very soon, but first, it’s time to properly define Functional Programming, so head on to the next article for that!

© 2021 Luis Ferrao — Powered by Jekyll & Poole