The Weary Travelers

A blog for computer scientists


Date: 2023-04-29
Author: Chris
Chris.png

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.

To view the Giscus comment thread, enable Giscus and GitHub’s JavaScript or navigate to the specific discussion on Github.

Footnotes:

1

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.