Go to statement considered harmful. Author: Edsger W. Dijkstra, Technological University, Eindhoven, The Netherlands View colleagues of Edsger W. Dijkstra . “GOTO considered harmful” needs to be read in its historical context, where structured programming (for Thanks for posting Dijkstra answer. One of the comments did mention Dijkstra’s article Go to Statements Considered Harmful, but aside from that mention, there was much.

Author: Douzahn Bragrel
Country: Cuba
Language: English (Spanish)
Genre: Software
Published (Last): 20 December 2015
Pages: 394
PDF File Size: 9.61 Mb
ePub File Size: 10.20 Mb
ISBN: 475-8-79216-330-6
Downloads: 99582
Price: Free* [*Free Regsitration Required]
Uploader: Akinojas

Some CPUs provide special instructions for implementing select statements directly in machine code by utilizing a small jump table.

It still has some relevance to today’s code. 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.

After each failure, however, resources must be deallocated. The question is analogous to the question of how we deal with a break statement: The execution is represented by the contents of the call stack and loop iteration stack at any given vonsidered during the execution – what Dijkstra calls the independent coordinates of the program execution, and what we might simply call the state or execution history of the program.

The following code uses a break statement to do this:. There’s also been a shift to using basic block-based optimizers, which means that the optimizer sees a loop statement and something built entirely of gotos as completely identical anyways.


Open the named file.

The code below is a C function that utilizes goto statements fairly effectively for error handling and recovery. My only experience was making error handling easier to understand. Roboprog on Feb 8, Thesis, antithesis, synthesis.

Therefore, according to Dijkstra’s criteria, continue and break statements have much less potential for harm than goto statements. It should also be realized that much of the terminology of programming that is taken for granted today had not yet been firmly established in For more complicated exits from loops, namely breaking out of a loop iteration that is nested within two or more levels of loops, more extensive support is required of the language.

Read the file header block if! The hope was that programming languages could be developed that made it possible to prove the correctness of programs.

Dijkstra did not mean that all uses of consieered were bad, but rather that superior control structures should exist that, when used properly, would eliminate considerwd of the uses of goto popular at the time. Such an infinite loop could indeed be written as a tail-recursive procedure call, but what would be the point? With each entry into a gotl clause, however, we can associate a so-called “dynamic index,” inexorably counting the ordinal number of the corresponding current repetition.

That’s a very common C idiom. Dijkstra still allowed for the use of goto for more complicated programming control structures. Imagine the authors horror had he witnessed the use of properties in modern object oriented languages!

Error handling being the most usual.

Go To Statement Considered Harmful: A Retrospective

Even keeping in gto that it was written with tongue haarmful cheek, Mr Dijkstra does sound like a bit of a jerk in this paper. Examples T-2 and N-1 demonstrate that Dijkstra’s maxim can be achieved provided that the programming language provides a reasonable set of control structures that can serve in place of simple goto statements.


Annotations by David R. GOTO isn’t all badthough. Dijkstra’s belief that unstructured goto statements are detrimental to good programming is still true.

Considered harmful

This is discussed further in Example L-1 and Example N-1 below. Some languages provide a continue statement for this:. In the absence of modern optimizing compilers this was very inefficient. It must be noted that Dijkstra’s final comment on the subject seems to imply that completely removing all of the gotos from consodered own programs is a bad idea.

This is designed to replace the multiple if-then construct, making it more obvious what the intended meaning is, i.

If you have a point to make, by all means, write a great persuasive essay. This is the Tao of goto: This second construct is the most obvious replacement for the unstructured test-and-goto construct:. In my last post, I mentioned a Usenet discussion about continue statements and their relation to goto statements, and said that almost none of the responses to that post went beyond the responders’ personal opinions.

We’ll consider each of these in turn.