Literate Programming

It turns out I've been using the wrong name for this all along. But I finally saw the light.

Graham Nelson, the creator of the Inform7 programming language gave a talk last year about making the Inform7 language open source. In this talk he referenced Donald Knuth's concept of literate programming, or a style of programming where your code looks like an essay.

For most of my career I've been calling this linguistic programming, as opposed to algorithmic programming. This is a differentiation in style; as both of them get you to more or less the same place: functioning code.

Software development occupies an odd space, mentally. It can be accessed either from a mathematical angle or an artistic one, or both. I've loosely defined algorithmic programmers as the ones who love recursive functions, because they are compact and mathematically pleasing.

Linguistic programmers are the ones who are in love with the ternary operator, because it makes a statement read like a sentence instead of like code.

Compare:

if ($value == $testValue){
   $x = $successValue;
}else{
  $x = $falureValue;
}

to

$x = ($value == $testValue) $successValue : $failureValue;

The first makes good programming sense. You can add more actions to the success case or failure case as needed. They do the same thing. But the second is a sentence, encapsulating a complete thought.

Names like “functions” or “methods” come from the mathematical side of software development. Statements like “code is poetry” come from the linguistic.

In my career I've met many excellent programmers in both disciplines. And many programmers who comfortably operate in either sphere.

I want to talk about the literate style of programming, and the value I see in it. When I was a professional programmer, I was definitely a literate/linguistic programmer. I wrote code as poetry, not as equations. I'm declaring this bias so you can rest easy; I know my bias, and I'm aware that my vision is skewed.

There are a few languages that favor a more literate style. SmallTalk, for example, is based in a concept of every object being effectively “alive”, sending and responding to messages like organelles responding to RNA. Much of what we use today in web development, like MVC (and derivative) frameworks were born in SmallTalk.

Perl, with it's frustrating syntax, was an attempt by Larry Wall to create a programming language that “thought” like humans. in perl there is a uniform way to say “the last variable you used”, which is insane by most programmer's standards. Why would you ever use that? Except you use that all the time in spoken language. It's called a pronoun.

And of course, there is Inform7, the only programming language I know of where the entire language is a subset of written English. Every statement in Inform is also a grammatically valid English sentence. And this is apt, since the sole purpose of the Inform language is to create interactive fiction.

So, why does any of this matter? I think the point here is that there are two equally valid routes into programming, but most CS programs teach programming as a “hard” science, meaning based in mathematics. And that's fine if you're doing computer science. We need the mathematical side to make code more efficient, to understand how we're using runtime, to basically advance the threshold of what we can do with machines.

But we also need the artists. We need the people who are more interested in CSS than compilers. We need the ones who will make computers sing and play and tell stories. For every Donald Knuth we need a Douglas Adams.

I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting 100 Days To Offload.

#100DaysToOffload 20/100

Thoughts? Tell me about them!
on Mastodon | on Twitter