Go To Statement Considered Harmful
loreprogramming
Dijkstra's 1968 letter arguing that unrestricted goto makes programs hard to reason about.
He contended that free-form jumps let control flow wander until you cannot follow the program's state, and championed structured constructs instead; the famous title was actually supplied by editor Niklaus Wirth. The piece won the argument, launched the 'considered harmful' essay format, and shaped how everyone writes control flow today.
Dijkstra's 1968 letter argued that unrestricted goto statements make programs harder to reason about, because the relationship between the text of the program and the state of its execution becomes arbitrarily complex. The title was supplied by the editor, and it spawned a genre of considered-harmful essays that continues today.
The underlying point survives the specific target. Dijkstra's concern was the gap between the static text a human reads and the dynamic behaviour it produces, and structured control flow narrows that gap by making the possible paths visible in the shape of the code. Loops and conditionals won not because goto is evil but because they let a reader reconstruct execution from the page.
The nuance usually lost is that Knuth's response, Structured Programming with go to Statements, is at least as important. His argument was that a blanket prohibition replaces judgement with ritual, and that some cases, notably early exit from nested loops and error paths, are clearer with a jump than with the contortions required to avoid one. Modern languages largely settled it by supplying break, continue, return and exceptions, which are goto with the destinations constrained.
Also known as: Go To Statement Considered Harmful, Dijkstra goto, considered harmful
Sources
- Dijkstra, CACM (March 1968)