|The Trick Of The Mind -The Strange Incident of The Goto Considered Harmful|
|Written by Mike James|
|Monday, 31 January 2022|
Page 2 of 2
So far so good. It sounds theoretically nice that all we need to create any flow of control in a program is the Goto – a single principle has to be simple? Yes, but what it can be used to create is far from simple.
Early programmers, indeed any programmers who used the Goto, tended to be opportunistic. What this means is that if they were writing some instructions and noticed that a Goto to some location in the list would be useful they just did it. The result is that most programs of the Goto era have a flow of control graph that resembles a bowl of spaghetti or tangled string. The Goto caused jumps to far flung locations within the program without any rhyme or reason to the innocent reader of the program. This made programs unintelligible even to the programmer who had written them!
This situation came to the attention of Dutch computer scientist Edsger Dijkstra who was very interested in the deeper ideas behind programming. He thought that programs were cleaner and easier to understand using a different set of constructs to the Goto. This was a revolutionary idea, but at the time programmers weren’t really interested in such elevated thinking.
In 1968 the idea that Dijkstra had come up with burst upon the wider world in a letter from him to the influential Communications of the ACM (Association for Computing Machinery) entitled, "The GOTO considered harmful".
The letter was an explanation of why the GOTO was a dangerous command in intellectual terms, but it also carried an emotional overtone which many found difficult to take:
"For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the density of go to statements in the programs they produce. More recently I discovered why the use of the go to statement has such disastrous effects, and I became convinced that the go to statement should be abolished from all "higher level" programming languages (i.e. everything except, perhaps, plain machine code). At that time I did not attach too much importance to this discovery; I now submit my considerations for publication because in very recent discussions in which the subject turned up, I have been urged to do so."
Dijkstra underestimated the magnitude of the task he had set himself. There are still programmers today who do not understand Dijkstra's argument, even though it has been refined over the years. Dijkstra coined the terms "goto-less programming" and "structured programming" and started a revolution in programming methods. However, this was not well received. The reason was that the machines that were running the programs worked in terms of Goto, which they generally called a “jump instruction”. What Dijkstra was suggesting was moving away from how the machine worked to something more abstract and hopefully better. This is a trend that continues today, but back then it seemed unnecessary and heretical.
Dijkstra continued his attack by singling out languages that used the Goto:
"The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense."
"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
The claim of “mental mutilation” may sound extreme, but it really isn’t far from the truth. Much of the resistance to the idea was due not just to the rational rejection of an idea that seemed unnecessary but an inability to see how to program using the new constructs. Even today, if a programmer encounters the apparent restrictions of structured programming they find it difficult to give up the freedom of the unrestricted Goto.
In book but not in this extract
It is difficult to put ourselves back in the position of the early programmers trying to do something on a regular basis that was once a rare occupation. The Goto incident is an example of the move away from the way programs are created to a more abstract view. In this case feelings were running high as programmers were being told that the way that they had been programming was very wrong and it was implied that they were damaged beyond recovery by the experience.
This may sound extreme, but in many cases it was true. It was difficult to see how obviously correct the Goto-less approach was because the people that needed to be persuaded were unable to see how to program using it. They saw it as an unnecessary straitjacket and confirmation bias made it possible to aggressively reject it.
It took a long time for programmers to see the error of their ways and retrain themselves to think in terms of the structured programming primitives. Even today you will still find new questions being asked on forums “What IS so bad about the Goto”, usually with a rider that the questioner wouldn’t dream of using a Goto or that they are asking for a “friend”.
Today there really is no dissent from the party line and all of the major programming language support structured Goto-less programming. What is perhaps strange is that many still have instruction labels and a Goto instruction often hidden in the documentation with big warning signs that something terrible will happen to any programmer who dares to use them!
Is there a better way than structured programming?
The Goto, Spaghetti and the Velociraptor
Edsger Dijkstra - The Poetry Of Programming
I TOLD You Gotos Are Dangerous!
The Trick Of The Mind - Programming & ComputationalThought
Buy Now From Amazon
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Tuesday, 01 February 2022 )|