How Programming Languages Find Inspiration in Literature

Karolina Gawron

How Programming Languages Find Inspiration in Literature

This article was written by Marta Paciorkowska based on the talk she gave at RubyConf Argentina.

The journey to Buenos Aires wasn't an easy one – both figuratively and literally speaking. It was one of those times when you send a talk proposal only to forget about it two minutes later. When my talk proposal got accepted, I realized it would be extremely difficult for me to afford to get to Buenos Aires.

After talking with some friends, I started a crowdfunding campaign to help me get there. Monterail was awesome enough to join in, supporting me with a couple hundred euros. If it wasn't for them (and many other people!), I wouldn't have made it. Thank you all!

What programming and literature have in common?

I'd like to start with a quote from Geoff Cox's awesome book Speaking Code:

Programmers express themselves through the use of program languages (…) in ways similar to other human communicative expression through language and gesture. They do this through their manipulation of layers of representation, including symbols, then words, language, and notation.

Let's try a very simple thought experiment and replace the word programmers with the word writers, and then again with the word poets.

It's still true: both programmers and writers express themselves through languages. Even though Christopher Marlowe did not make Doctor Faustus recite Perl scripts, communicating with Perl scripts requires some decent knowledge. Knowledge of a full, proper language, with its set of grammar rules, a vocabulary, syntax, and idioms for the more advanced users.

A bit later in his book, Cox also writes:

If program code is like speech inasmuch as it does what it says, then it can also be said to be like poetry inasmuch as it involves both written and spoken forms. The analogy to poetry suggests numerous aesthetic and critical possibilities for code, beyond its serving simply as functional instructions.

You can start with stating the cliché: that both writing code and writing poetry is creative, and then work from there, looking for a less worn out statement. You can say that programming languages and works of writing serve similar purposes. Cox writes about aesthetic possibilities for code and later in his book introduces numerous examples of computer programs or conceptual scripts that serve aesthetic, social and/or political purposes.

Graham Harwood's Class Library is a great example of a piece of writing which can be read as a collection of programming scripts as well as socially engaged poems. And if they (programming languages and written forms of art) can serve similar purposes and have similar traits, they can also undergo similar processes and are both open to critical interpretations.

Keeping that in mind, let's look at 99 bottles of beer written in Brainfuck by Ben Olmstead.

Brainfuck is a very special language: each program is a sequence of just eight characters and each character is a separate instruction. It turns out a set of eight instructions is enough to build an elegant, Turing-complete language.

Although some people will call Brainfuck hilarious (and it might be hard to take a language with an NSFW name seriously), its minimalism is worth looking at closely: Brainfuck is a postmodern programming language.

Postmodernism in literature and programming

Postmodernism is an artistic and cultural movement that dates back to the second half of the last century. In literature, postmodernism explores new artistic techniques. That's when writers start to deconstruct natural languages, poets and storytellers cut languages into chunks, shuffle them, show that nothing in language and its meaning is obvious. This E. E. Cummings poem is a beautiful example of such defragmentation. It's the essence of minimalism, although the form looks quite complex – something the reader isn't accustomed to. It's just one sentence, Nothing can surpass the mystery of stillness, but its format on the page together with the typography obscure the actual meaning. It tests you. It's a trial.

Brainfuck is postmodern in the same way some other esoteric programming languages are: it looks like its creator, Urban Müller, deconstructed a programming language in a thought experiment. Not all of these languages are supposed to be useful; they are but an exercise of the author(s), pushing them – and the reader/writer (author/user) – to the proverbial extremes.

It makes us question the list of the obvious traits a programming language can have (such as readability, brevity or quick translation). I find similarities between them and postmodern poetry quite telling.

On the other end of the postmodern spectrum, there are languages like Malbolge (created by Ben Olmstead), whose Turing-completeness is subject to speculation, and its HEllO WORld program – written by an algorithm designed by a human.

Have a look at the code. In the case of Malbolge, usefulness wasn't even a desirable trait! Quoting Wikipedia:

Weaknesses in the design have been found that make it possible (though still very difficult) to write useful Malbolge programs.

It brings to mind poems like A defense of Poetry by Charles Bernstein. It is both similar and different to n (just like Brainfuck and Malbolge). It's very difficult to read out loud and its meaning is obscured. The deliberate typos draw the focus away from the content of the poem and force the reader to focus on the highest layer of the text. All that makes it harder to understand the sentences and the meaning of them as a whole. It's not trying to stick to the essentials, like n. On the contrary, it's making things difficult for you on purpose. Does it mean you won't enjoy it, though? No.

Natural language and ease of communication

Interdisciplinary poetry and esoteric languages are not where similarities between culture and programming end.

A quote from a very interesting article by Jean E. Sammet should bring us closer to what was considered the Holy Grail of programming at that time (the beginning of 1970's) and obviously, also a bit earlier: having a programming language that reads like a natural language:

The ultimate ease of communication with the computer allows the user to specify his [sic!] instructions—or wishes—in a natural language such as English. That is a shorthand way of saying that the user could use his native language, including notation (e.g. Algebra, molecular diagrams) appropriate to his particular field. This concept does not envision one single computer system understanding all of English. It does envision many systems, each of which is capable of dealing with a particular field, specifically including its specialized jargon.

Resembling a natural language is an important characteristic of most higher-level languages and does not sound like something revolutionary to people used to coding in them.

A look at Assembly code or machine code should give a valuable insight into how important this evolution was.

At the same time, it shouldn't come as a surprise that at that time there were more important things to focus on than having a syntax you could become friends with. But with AppleScript, the Shakespeare programming language, some other languages created purely for fun, Cucumber's Gherkin (hey, why not?), and most notably Python and Ruby (emerging in the early nineties) with their English-like vocabulary, the trend started coming back.

Ten years later, the same two languages slowly started being advertised as languages with an English-like syntax.

Ruby's English-like syntax makes it one of the best languages to use as an introduction to the world of programming.

A language having an English-like syntax means that in certain circumstances a program written in that language can be read like a paragraph written in a natural language: there will be English-like vocabulary, there will be subjects, verbs, and objects (instructions and class and method names, etc.), and so on.

When you learn a new natural language, you'll often find yourself wanting to use words that you don't know yet. Since I'm learning German right now, I'm experiencing it first-hand, adding ge- to each verb, I want to use the past tense, or producing female-gendered nouns on a mass scale by adding -erin to random words. Sometimes it works, sometimes it doesn't – like a lot of intuition-based solutions – but recognizing rules like that in a natural language helps you improve the knowledge of that language, even if you make a mistake here or there.

Ruby, a programming language, is a bit like that. Quoting Steve Yegge:

It's so consistent that you start being able to guess how things work.

The feeling of familiarity when reading simple Ruby code is an advantage. Obviously, not all Ruby will look like Simple English, but the possibility of crashing into more advanced programs on the first contact is minimal. The fact that Ruby's standard library has a natural sounding method and class names whose actions and responsibilities can often be predicted based on their names definitely helps.

Would you be willing to believe programming is like speaking or like writing poetry?

That programming languages can be as postmodern as contemporary art? Even though it may sound controversial at first, this comparison is in no way fresh off the presses. Programming languages, their long evolution and the people that create and maintain them do not exist in a cultural vacuum. The way our field evolved through time resembles the processes other fields went through. When a community decides to grasp being interdisciplinary, everybody wins.

For example, think of translators teaming up with engineers specializing in natural language processing to develop the fascinating field of machine translation. The way we, as programmers, express ourselves, what we learn and how we code is strongly connected to the culture that surrounds us.

Karolina Gawron avatar
Karolina Gawron