Edsger Dijkstra - The Poetry Of Programming
Written by Mike James   
Thursday, 29 October 2020
Article Index
Edsger Dijkstra - The Poetry Of Programming
GOTO considered harmful

Edsger Dijkstra was one of the first people to worry about what a program should be and he elevated the act of programming to both an art and a science. If you only know one Dijkstra quote, it should be: "computer science is no more about computers than astronomy is about telescopes".




Some might say that the history of software is still with us - just look at any computer to see it!

But software isn't as durable as hardware and trying to trace who invented the great ideas is difficult. More to the point it can be next to impossible to identify what the great ideas were, because once discovered, most of them seem obvious.

Can it really be that someone had to invent the Goto command, the array, the variable?

It was a slow struggle to see what programming is all about and Edsger Dijkstra had the distinction of seeing more clearly, sooner than the rest of us.



Edsger Wybe Dijkstra (1930 - 2002)


How It Was

Back in the early days of programming it was natural enough to think in terms of building lists of instructions. Mostly the instructions were obeyed one after another in the order in which they were listed - but the real power came from instructions that could change the order of execution.

A jump instruction can make any instruction in the program the next one to be obeyed. In fact at the machine code level it is all to easy to write a jump instruction that transfers control into the middle of another instruction and so create complete rubbish!

Conditional jump instructions extend the idea to making a test and then only performing the jump if the test turns out true or false. Using jumps and conditional jumps programmers quickly invent for themselves loops of various sorts and the equivalent of "if" statements.

To a modern programmer this doesn't sound too surprising.

What is surprising is that programmers brought up on jumps often don't think in this way. They don't think "I need a loop here" they just code the instructions that represent the first time through the loop and then they notice that they need to do the whole lot again and so use a GOTO or whatever transfer instruction the machine supports to get back to the start.

What this means is that they could and still can write programs without any clear idea of what is going on at the larger scale. You could say that the building blocks used by the early high level programmers were modeled on what the machine provided and what the machine provided was simple because hardware has to be simple. So you put a program together with conditionals built from if..then goto and loops put together with goto and if..then goto. 

What is wrong with this "programming by the seat of the pants" approach?

The answer is that if you aren't clear what you are using the GOTO for you tend to use it for any reason that comes to mind.

This may not sound like a problem but the result can be a completely tangled program. Imagine that you have in front of you the text of a well written program. Now take a pair of scissors and cut it up into random chunks. Shuffle them and stick back together with tape. The resulting program now doesn't work but to make it work all you have to do is put GOTO instructions at the start and end of each shuffled chunk to make the order of execution the same as it was before the shuffle.

You may have a working program but now it is very difficult to understand and as a result difficult to modify. A program that is a mess tends contain bugs and this was the big problem in the late 60's. People wrote programs by looking the next piece of code that needed to be executed and writing a GOTO to get them there. The result was usually called spaghetti code because you got a tangled mess if you took your finger and traced through all the possible execution paths.

Enter Dijkstra

Edsger Dijkstra was born in 1930 in Rotterdam and studied mathematics and theoretical physics at Leiden. By a series of coincidences he ended up programming one of the first computers in Holland, at the Mathematical Center in Amsterdam.

He eventually found that pursuing physics and using a computer were difficult to combine and so one day in 1955 he went to talk to his boss, Adriaan van Wijngaard, about becoming a professional programmer.

He was troubled by the fact that it wasn't entirely clear that programming was a respectable intellectual discipline - like theoretical physics. Van Wijngaard had to agree that there wasn't much substance to programming but Dijkstra might like to consider doing something about it, after all computers were clearly here to stay. As Dijkstra explained in his 1972 ACM Turing Lecture:

"When I left his office hours later, I was another person"

who was motivated to play a part in putting the unknown discipline on the map.

To illustrate just how unknown a subject programming was, when Dijkstra was getting married two years later he stated his profession as "programmer", but this wasn't acceptable on that grounds that there was no such profession and he had to change it to "Theoretical Physicist"!

Over the years Dijkstra worked on ways of making programming more organised and logical but he also had a deep sense that what mattered was clarity and elegance. He didn't always feel this way. Back in the early days of programming making your routines fit into the available memory and other questions of efficiency were more important.

Programmers would challenge one another with the task of writing the shortest program without any thought that the shorter program might be totally unintelligible. The use of coding tricks was thought to be the mark of a great programmer. We still do this today and yes we marvel at the tricks but we know that they are tricks and we don't try to build them into production code. 

Even Dijkstra wasn't above such competitions but he probably didn't expect his colleagues to go to such great lengths to get the upper hand. Dijkstra offered a free meal to anyone who could write a shorter routine than his for some problem or other - apparently a bold bet for an archetypal Dutchman!

He lost his one and only bet because Carel Scholten, the man who had designed and built the computer that Dijkstra was using, modified it and secretly added an instruction that would allow him to write a shorter program.

Dijkstra later said,

"Two opinions about programming date from those days. I remember them now.

The one opinion was that a really competent programmer should be puzzle-minded and very fond of clever tricks; the other opinion was that programming was nothing more than optimising the efficiency of the computational process".

Despite his early seduction by the tricks of program coding, Dijkstra slowly worked his way towards the idea that programs should be clear expressions of algorithms.

He noticed that there was a purely theoretical side to computing. You didn't need the actual hardware if you had a logical description of how the machine behaved. In fact it was a blessing to get away from the real world of hardware and concentrate on the purity, and even beauty, of the software.

One of his sayings sums up the idea perfectly:

"computer science is no more about computers than astronomy is about telescopes".









Last Updated ( Thursday, 29 October 2020 )