21
21
Feb 2009

Reviewing “GOTO Considered Harmful”

I just looked into an old paper– “GOTO Considered Harmful”– and I found something bitter about EWD (Dijkstra).

GOTO is understandably bad from a present-day perspective; it allows a thread to jump to basically anywhere in a process, and even in situations where it is used respectfully, it is difficult for the programmer to indicate so in his or her source code. But GOTO did something that lots of people could appreciate; it allowed an inner loop to break out of an outer loop. It essentially allowed a complex iterative process to end before the iteration could be completed, without any nutty boolean flags.

Nineteen years after Dijkstra’s rant against GOTOs, a guy named Rubin wrote a counterargument. (This was in 1987, about the time I was born.) By then, GOTO-independence was almost a religious (read: irrational) doctrine. Rubin’s rebuttal reinitialized dialogue about GOTOs. Most people involved in the discussion pointed out that the strength of GOTO could be inherited by some sort of more restrained flow control successor, one that couldn’t just jump around the process. [It should be noted that the formulation of our most common present-day flow control statements were highly influenced by EWD. -Ed.] Rubin’s stance was that at the time, code that used GOTO properly was less cluttered and more readable than code written to deliberately avoid GOTO, and that therefore EWD’s 1968 proposal to eradicate GOTO had a harmful effect on programming efforts.

Dijkstra replied, and here’s what gets me; he noted some errors in Rubin’s code– mostly failures to comply with an orthodox writing style– lambasted him for being an amateur, used computer science to achieve a difficult-to-read solution to Rubin’s example problem, and basically called the man and the other contributors to the conversation “unprofessional”.

It’s too bad the discussion didn’t take place yesterday, or I’d troll him on a message board somewhere.

I believe and can understand that Dijkstra was coming from a different perspective- a highly technically informed one. He was in the middle of a major movement attempting to bridge programming with highly abstract mathematics. But programmers typically will not pour over algorithms to produce code, mainly because it reduces the reader’s comprehension, a principle ironically similar to EWD’s original incentive to ban GOTO in the first place! Wouldn’t it be better to write code that can be understood by those responsible for maintaining it?

This is what the creators of ActionScript 3 had done. [Apparently this language element was inherited from Java. -Ed.] In a situation where code in an inner scope needs to break from an outer scope, the “break” statement can refer to the name of a scope that it is nested within. The following code uses this principle to report the index of the first row composed only of zeros in a 2D matrix of integers:

  1. function firstEmptyRow(arr:Array):int {
  2.  var rows:int = arr.length, columns:int = arr[0].length;
  3.  rowLoop: for (var i:int = 0; i < rows; i++) {
  4.   columnLoop: for (var j:int = 0; j < columns; j++) {
  5.    if (arr[i][j] != 0) {
  6.     break columnLoop;
  7.    }
  8.   }
  9.   return i;
  10.  }
  11. return -1;
  12. }

You see? Comprehensible, expressive. Powerful. Anyone who is familiar with C syntax would have no trouble understanding this. Even Python users would be fine with it (though I’d take the curly braces out first, the pansies).

In conclusion: GOTO had serious problems, and it’s good that it’s gone. And Dijkstra’s contribution to computer science and programming has been invaluable. But his rebuttal was far less sensible than his original proposal; his personal attack on Rubin did nothing to inform the readers on the problems surrounding GOTO, but instead revealed his intolerance for programmers who were more down-to-earth than he is.

References!

[-1] “GOTO considered harmful”, EWD
[0] “‘GOTO considered harmful’ considered harmful”, Rubin
[1]“‘”GOTO considered harmful” considered harmful’ considered harmful?”
[2]“On a somewhat disappointing correspondence”, ugh, EWD


You can leave a response, or trackback from your own site.

Leave a Reply