Back in the Smalltalk days when OO was birthed, the idea was to have a bunch of objects that pass messages to each other. The focus was supposed to be on the messages.
But people like objects. They are easy to draw on a white board. And they come with cool tools like inheritance and polymorphism. Pretty soon these tools became the focus. People learned how to use them, and used them willy-nilly. All that worry about messages was left in the dust.
It’s almost like wanting to be a surgeon, so I learn how to use all the tools that a surgeon uses. Get certified in scalpels and retractors and ultrasound tissue disruptors. And bam, I’m a surgeon! Hire me, I can operate on anybody!
Functional programming is still in its youth. Which tools of the trade will become synonymous with functional, as its principles are left in the dust? The point of FP is making each piece of code interchangeable with its return value. Expressions that can be evaluated in whatever order, or never if they aren’t needed. Whatcha wanna bet people learn how to pass functions around, and start considering themselves functional programmers?
Objects that pass themselves and give access to all their innards are the opposite of the original intent of OO. When FP goes mainstream we’ll have side-effecting, environment-dependent functions passed around willy-nilly. “What do you mean I can’t pass this code over the network?” they’ll say, and RMI will be enhanced to Remote Method Passing, and committees will publish protocols.
OO was originally method-oriented. FP is more accurately expression-oriented. People get hung up on what they can do with the tools these paradigms offer. The essence of each is not what we can do, but what we don’t do. Objects don’t muck around with each others’ state, so we can be sure the code that sets, changes, and uses this data is right here with it. Functions don’t use or impact the outside world, so we can be sure this input entirely determines this output.
Reuse isn’t about typing. Characters are free. It’s about saving headspace: throw this task over a wall to some code I trust. Then I don’t have to worry about design, naming, or testing. But wait, can you trust that superclass? only if you’re diligent about enforcing LSP and various other principles we aim for as we try to use OO tools without stabbing ourselves with the scalpel. Functional programming will become just as painful if we let go of principles and hold tight only to the tools.
As a surgeon, I can excise your kidney, snip off those tonsils, or cut that baby right out of your uterus without stretching your vagina. But should I? The essence of medicine is guessing the right procedure for each patient. Most of the time, the right surgery is no surgery.
Therefore: Abuse of inheritance is like cutting out your kidney to cure the flu. And returning any old function from another function is using radioactive iodine to cure one cancer and cause another.
Maybe we should all take an aspirin and go to bed.
—————
The sage responds:
“The adoption of new paradigms leads to the formations of patterns of
their misuse. And their replacement by other paradigms. Why should
this discourage you? It is the way we learn.
(Shrugs shoulders) Purity is a matter of perspective. Software is for
helping people.”