Don Knuth's Take on the Temptress "goto", from 1974

I was reading a thread on Hacker News the other day about a revival of the "gotos are harmful" argument, and someone referred to an article by Don Knuth from 1974 about goto's that I was not familiar with - "Structured Programming with go to Statements". Although it's 40 pages or so, with more than 100 references, much of it is written in an informal style more akin to something you'd read on a blog today, not a technical journal.

He writes that his purpose was to present "a reasonably comprehensive survey of the go to controversy" in an "apparently vacillating manner" - a manner he was apparently quite pleased with:

I tried this approach when I lectured on the subject at UCLA in February, 1974, and it worked beautifully: nearly everybody in the audience had the illusion that I was largely supporting his or her views, regardless of what those views were !

And what was his view? He teases, saying he won't take "a strong stand one way or the other until the discussion is nearly complete."

And he waxes hopeful for a "really good" language to come, and muses whether it will contain the "go to" or not. He also vacillates on the name for this language as well - should it be "Utopia 84" or "Newspeak"? He never answers that question. Nor has history, for that matter. Maybe he meant Utopia 2084.

And, what is the big ending as to his opinion on the matter? I (somewhat appropriately) did a goto to the end:

I personally wouldn't mind having go to in the highest level, just in case I really need it; but I probably would never use it, if the general iteration and event constructs suggested in this paper were present.

Of course, looking back from our vantage point forty years in the future, neither the controversy nor the goto itself has been made obsolete. Just the other day, I spotted a goto in the javascript array sort method in the source code for Chrome - it is a quicksort implementation, and the convenience of the goto to easily get out of a nested loop was just too much temptation to resist. A temptation Knuth knew all too well:

The question is whether we should ban it, or educate against it; should we attempt to legislate program morality? In this case I vote for legislation, with appropriate legal substitutes in place of the former overwhelming temptations.

N.B. Knuth mentions a funny spoof paper by R. Lawrence Clark in 1973 concerning the new "come from" statement ["A linguistic contribution to GOTO-less programming, " Datamation 19, 12 (December 1973), 62-63].

Popular Posts