A Case Against the Goto Statement
Dijkstra, Edsger W. “Letters to the editor: go to statement considered harmful.” Communications of the ACM 11.3 (1968): 147-148.
Summary
Quality of a program empirically seems to negatively correlate with the prevalence of go to statements, (and he even goes so far as to link it with the quality of the programmers themselves). Why?
- He observes that humans are terrible at modeling dynamic systems but are not bad at recalling static ones. Hence the greatest aid comes from preserving the direct relation between static text sequence and dynamic execution sequence.
- He introduces, and later extends, a notional textual index that links a location in the static text with a location in dynamic state space.
- “The main point is that the values of these indices are outside the programmer’s control.”
- “The unbridled use of the go to statement has an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress.”
- As a final aside, mechanical removal of go to is not recommended either, implying that doing so would produce something worse yet – it’s not the presence of the go to that’s harmful, but rather the inclusion of it at design time that obliterates the needed linkage between text index and state index.
My Observations
- He goes out of his way to credit people who may have sparked the idea, and also appealed to others as to why he sent the letter in the first place. This tells me he’s aware of how deeply subjective – and sensitive – the topic is, which is rare for a computer science paper, though, I can’t say I’ve read all that many letters to the Editor in CS journals either.
- He echoes the sentiment found in Knuth’s conclusions1Structured Programming with go to Statements
Knuth, ACM Computing Surveys 1974
This paper is also incredibly personal by today’s standards. Knuth is highly diplomatic about the controversy, and spends more than a few words on the personalities involved. that go to’s are not harmful in themselves so much as they are indicative of an incompletely or improperly designed program. Simply removing them mechanically is possibly even more harmful because it further disrupts the linkage between text and state indices.
Comments
Comments can be left on twitter, mastodon, as well as below, so have at it.
New post!
— The Weary Travelers blog (@wearyTravlrsBlg) April 29, 2023
Suhail’s outline of "A Case Against the Goto Statement"https://t.co/TLiRGQSKMB
Chris’ outline of "A Case Against the Goto Statement"https://t.co/7LEdaLGXLq
Footnotes:
Structured Programming with go to Statements
Knuth, ACM Computing Surveys 1974
This paper is also incredibly personal by today’s standards. Knuth is highly diplomatic about the controversy, and
spends more than a few words on the personalities involved.