"For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the density of go to statements in the programs they produce. More recently I discovered why the use of the go to statement has such disastrous effects, and I became convinced that the go to statement should be abolished from all "higher level" programming languages."1

With this statement, Edsger W. Dijkstra finally removed computer programming from the realm of electrical engineers and established it as an independent science. The title has been the inspiration for any number of imitators.

In this brief article, Dijkstra asserts that the purpose of a program is to model a process, and that well-written programs lay out the process in a straightforward manner.

To begin with, the "textual index" or line number is a particularly poor indicator of a computer's position in such a process. Dijsktra advocated the replacement of textual indices into the source code with a "dynamic index" into the state machine represented by the program.

Now, most uses of GOTO were really attempts to represent higher level structures (branching, looping, and abstraction) within a program.

But GOTO (the largest consumer of textual indexes) is a crude tool, allowing the programmer to jump from anywhere to anywhere else. If a program instructs the computer to jump willy-nilly throughout the program (spaghetti code), it becomes difficult to determine the state of the program, and impossible to reconstruct the process later. With ALGOL's introduction of the procedure, not only were GOTO statements made superfluous, they were dangerous. For example, it became possible to jump from the middle of one procedure to the middle of another!

Dijkstra actually goes a bit further, stating that IF and WHILE were contained forms of GOTO, and were superfluous and replaceable by recursive procedure calls. The dynamic index would then be directly embodied in the program's call stack. He allowed, however, that hardware limitations made it impractical to replace IF and WHILE statements, and that the latter had some intuituve appeal.

Thus started the revolution of structured programming.

In the early 1980's, some began to consider this view a bit dogmatic. People began to point out a construct that could not be handled with a dynamic index: the need to exit from several nested levels of procedure or a loop early. There was even a paper titled "'Go to statement considered harmful' considered harmful". In my sophomore-year programming class, a project was failed if its code (in Pascal, of course) contained even one GOTO. In my junior-year programming class where I was told to unlearn some of what I had learned, and allow GOTO drains (or abortion clauses as Dijkstra termed them). Later on, of course, this was all replaced with exception handling2.

1Communications of the ACM 11, 147-148. © 1968 ACM, filtered through http://www.acm.org/classics/oct95/

2mkb sez "replaced with exception handling" except in languages or environments without exceptions, or in shops where exceptions are considered harmful.

Log in or registerto write something here or to contact authors.