Skip to content

Instantly share code, notes, and snippets.

@Pzixel
Created August 28, 2019 11:35
Show Gist options
  • Save Pzixel/19bdff4739d608aae54188c436d69117 to your computer and use it in GitHub Desktop.
Save Pzixel/19bdff4739d608aae54188c436d69117 to your computer and use it in GitHub Desktop.
Functional programmers have a peculiar way of approaching problems.
They start by asking very Zen-like questions. For instance, when designing an
interactive program, they would ask: What is interaction?
When implementing Conway’s Game of Life, they would probably ponder about the meaning of life. In this spirit, I’m going to ask: What is
programming? At the most basic level, programming is about telling
the computer what to do. “Take the contents of memory address x and
add it to the contents of the register EAX.” But even when we program
in assembly, the instructions we give the computer are an expression of
something more meaningful. We are solving a non-trivial problem (if it
were trivial, we wouldn’t need the help of the computer). And how do
we solve problems? We decompose bigger problems into smaller problems.
If the smaller problems are still too big, we decompose them further, and so on.
Finally, we write code that solves all the small problems.
And then comes the essence of programming: we compose those pieces
of code to create solutions to larger problems. Decomposition wouldn’t
make sense if we weren’t able to put the pieces back together.
This process of hierarchical decomposition and recomposition is not
imposed on us by computers. It reflects the limitations of the human
mind. Our brains can only deal with a small number of concepts at a
time. One of the most cited papers in psychology, The Magical Number Seven, Plus or Minus Two1
, postulated that we can only keep 7 ± 2
“chunks” of information in our minds. The details of our understanding of the human
short-term memory might be changing, but we know
for sure that it’s limited. The bottom line is that we are unable to deal
with the soup of objects or the spaghetti of code. We need structure not
because well-structured programs are pleasant to look at, but because
otherwise our brains can’t process them efficiently. We often describe
some piece of code as elegant or beautiful, but what we really mean is
that it’s easy to process by our limited human minds. Elegant code creates chunks
that are just the right size and come in just the right number
for our mental digestive system to assimilate them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment