M. Lanza

Functional Core, Imperative Shell

An architecture for wrangling side effects

There’s immense value in learning to separate the functional core from the imperative shell in the programs you write. With this approach, you take the ideas which make up the domain, the thing your program is actually about, to a safe, simple, testable realm.

In this realm, programs are easy to reason about and develop. It’s so safe it’s almost boring. “Mundane,” some might say.

There are no children running with scissors. There are such children, yes, but they’ve been relegated to the other place—the one only spoken about in hushed voices. And, you can choose, when you dare, to venture there for, whether or not you know, it’s a place you must go. It’s just convenient being able to choose when you’re ready for it.

I’ve had great results separating programs into cores and shells. I’ve used the approach professionally and independenty in all contexts—including enterprise apps, puzzle games, and 2D classic video games. It works predictably well everywhere.

Sample programs

I credit Rich Hickey, a mentor in that his creation, Clojure, and illuminating talks set me on a path which restored a delight in programming which continues to this day.

Interacting from the console

Going forward, assume the code you encounter is the seed of an Atomic app running from an HTML page. You’ll be mirroring the examples and practicing what you’re seeing to bolster your understanding.

So anticipate setting up, serving web apps and interacting with them in the browser console precisely as explained in Getting Started. Ensure, also, you grasp how the registry is used to faciliate interactive development as that’s central to everything.

A way of thinking

You’ll be taught a way of thinking, gleaned from Hickey and others, that is library and language agnostic. That’s transferrable skills and concepts, not Atomic. It’s just to create and run programs concrete choices must be, and have been made.

A basic understanding of HTML, CSS and JavaScript is presumed. None of the lessons walk you step by step to completing anything. Rather, they guide and teach you something important about building apps using the prescribed approach. They’re big picture more than paint by number. Your job is to apply the lessons so they sink in.

By the time you’ve finished the book and written a few programs, you’ll grasp how to separate a functional core from its imperative shell. Moreover, you’ll understand why it’s such a very good thing.

ML