Dijkstra's Mozart

Jul 02, 2017 — Tags: Musings

Approximately two years before his death, Edsger Dijkstra was interviewed by the Dutch television program Noorderlicht. On that occasion he made an interesting comparison between two programming styles, which he characterized as Mozart versus Beethoven.

The full quote, transcribed here from the subtitles, is as such:

There are very different programming styles. I tend to see them as Mozart versus Beethoven. When Mozart started to write, the composition was finished. He wrote the manuscript in one go. In beautiful handwriting too. Beethoven was a doubter and a struggler who started writing before he finished the composition. And then glued corrections onto the page. In one place he did this nine times. When they peeled them, the last version proved identical to the first one.

That iterative method of programming is somehow a very Anglo-Saxon custom. British education is pervaded by it. People learn, when they write, not to try to get it right the first time. Just write what’s on your mind and then rewrite repeatedly to get the product you want. That’s partly why word processors are marketed so aggressively and partly why they have been so successful here. While it is one of the advantages of working with pen and paper that when you start a sentence you should have it ready.

— Edsger W. Dijkstra1

Although it is not mentioned explicitly in the above, there can be little doubt that Dijkstra considers the Mozart style to be superior – especially if you consider that Anglo-Saxon is a pejorative in Dijkstra’s vocabulary.

Admittedly, the metaphor is an inspiring one: the image of a wise man pondering a problem on long walks, writing down the whole thing only when all is clear in a single sitting (preferably with a fountain pen) is certainly romantic.

The image may especially rouse feelings of nostalgia when contrasted with the daily reality of trying to stay afloat in an ever increasing see of garbage. In a time where getting software out the door as quickly as possible is the all-overriding concern Dijkstra’s focus on elegance comes as a breath of fresh air.

However, like most romantic images, the metaphor does not survive a closer examination.

The Mythological Mozart

The first problem with the Mozart style of programming is that the image that Dijkstra presents of Mozart is itself largely a mythological construction.

The myth that Mozart composed his music fully in his head before committing anything to paper has its roots in a large part in a letter of which a key passage is presented below. It was published in 1815, more than two decades after his death, and addresses a certain “Baron von —”:

When I am, as it were, completely myself, entirely alone, and of good cheer; say travelling in a carriage, or walking after a good meal, or during the night, when I cannot sleep; it is on such occasions that my ideas flow best and most abundantly. [..] Those ideas that please me, I retain in memory [..] and provided I am not disturbed, my subject enlarges itself, becomes methodized and defined, and the whole, though it be long, stands almost finished and complete in my mind, so that I can survey it, like a fine picture or a beautiful statue, at a glance. Nor do I hear in my imagination the parts successively, but I hear them, as it were, all at once. [..] What has been thus produced I do not easily forget [..]

When I proceed to write down my ideas, I take out of the bag of my memory, if I may use that phrase, what has previously been collected into it, in the way I have mentioned. For this reason, the committing to paper is done quickly enough, for every thing is, as I said before, already finished; and it rarely differs on paper, from what it was in my imagination. At this occupation I can therefore suffer myself to be disturbed; for whatever may be going on around me, still I write.

— not Mozart2

This letter was already exposed as a forgery in the 1860s3, but this did not stop the myth from being perpetuated.

Contrasting with the forgery are multiple surviving letters that are known to be authentic. First, letters sent by Mozart’s mother on their joint arrival in Paris describe first how bored he is without a keyboard in the room. A second letter describes hat, when it turns out that the stairs are too narrow to carry a keyboard to the room, that Mozart will need to do his composing away from home. A third, sent Three years later by Mozart himself upon moving to Vienna, describes how renting a keyboard is his first priority, so that he may turn to composing as soon as possible.4

The decision, made after his death by his widow Constanze, to throw away all drafts of completed works, and keep only sketches and drafts of uncompleted ones helped to establish the 5 myth that Mozart wrote down his compositions in a single writing. Fortunately, plenty of sketches remain to show to us that Mozart used sketches extensively in his creative process (albeit perhaps not as extensively as Beethoven) throughout his career; one of such sketches is shown at the bottom of the image below.

The research into the myth versus reality of the Mozart’s compositional method is extensive enough to have its own Wikipedia page.

An example of surviving "work in progress" by Mozart

Bigger problems

Let’s step away from the specifics of Mozart for a moment, and consider the merits of the Mozart programming style independently of the truth of chosen example.

A simple observation is that even the greatest genius has a limited mental capacity. Assuming an equivalent of the mythological Mozart exists in the realm of programming, at some point this mental capacity runs out. Applied to programming: you may be able to understand a single small or medium-sized program fully at once; but at some point, the program as a whole becomes too large to fit in a single person’s head in full.

With the risk of of starting a flame war, we might also wonder which art has the greater capacity for complexity: that of composing music or programs? Firstly, we might observe that the length of programs has almost no theoretical upper bound, whereas a musical composition’s length is bounded by the endurance of the human bladder. Secondly, let’s see what Dijkstra himself has to say about the subject:

Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.

— Edsger W. Dijkstra, EWD498

In short: If you can solve a problem entirely in your head, perhaps you should be working on bigger problems.

Changing circumstances

There is one more critical difference with with music: whereas a piece of music may at some point be finished, many programs are, by design, never finished.

This is at least true for the class of software that is often labeled “business software”: Software that models the processes of a real-world organization to be able to facilitate its real-world processes. Examples are programs to calculate insurances premiums, facilitate logistics and collect taxes; some of such programs are implemented specifically for any given organization, others serve an entire market. All such software must be changed whenever the real world it is modelling changes, and is only finished when the organization it’s supporting dies.

The ever changing nature of programs is also caused by the fact that the existence of the software may create further wishes to change it. Just like Mozart couldn’t compose without a piano and many programmers cannot program without a keyboard, many organizations cannot compose their requirements without the feedback of an actually working program. That learning about the requirements of a given program can only be meaningfully done with an actual running version of the program is one of the central tenets of the Agile movement.

Applying the model of the mythological Mozart to ever changing requirements asks of us to believe in a programmer that cannot only see the current version of a program in their head in its entirety, but also possesses the skill of foreseeing the future - quite a feat indeed!

Conclusions

Aspiring to elegance in programming is laudable; given the state of our field it can’t really hurt to raise the bar a bit by listening to Dijkstra’s words.

Let’s not base this aspiration on a mythical vision of Mozart and the human creative process though. The creative process is messy; requiring experimentation, drafts and interaction with our instruments. Let’s look out for tools that facilitate this, rather than base our hopes on a small group of geniuses.

Let’s also realize that software does not operate in a static environment: writing the best version 1.0 we can, knowing full well that there will be a version 2.0.

Beethoven is still widely considered one of the world’s best composers by any measure. Perhaps his methods weren’t so crazy after after all.

  1. The video is available at the Edsger W. Dijkstra Archive and on YouTube; the relevant quote starts at 4:20. 

  2. The letter was published in German 1815 in the Allgemeine Musikalische Zeitung, the English translation above is from the 1825 Harmonicon 

  3. The fact that the letter is a forgery was first pointed out by Otto Jahn, in his biography “Life of Mozart”. 

  4. From the Cornell University Library’s Division of Rare and Manuscript Collections - Tell-Tale Letters 

  5. From the Cornell University Library’s Division of Rare and Manuscript Collections - How did Mozart Compose?