“GOTO Considered Harmful” Considered Harmful (1987) [pdf]
web.archive.org
web.archive.org
Optimizers have also gotten better over the years--it would be fairly easy to transform the idiomatic find-loop pattern based on flags to the one that uses the goto. 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.
So, in the end, the goto debate is moot: there's no real difference in performance either way these days, and we've renamed the goto instruction to break which sidesteps most of the puritanical section of the debate.
And there is a huge performance difference between a computed `goto` implementation of a VM vs. a switch-based one.
Break is not a substitute for any of this use cases.
People forgot that any language gets converted into assembly language and it has JMP or JUMP statements in them that basically do the same thing as a GOTO in a higher level language.
I wrote Visual BASIC 6.0 code and in order to trap errors we had a On Error Goto ErrorHandler: where we had an error handling routine that would do a customized message box to give the user more information on the error and prevent the program from ending. I would give recruiters samples of my VB code and it had On Error Goto and they saw the Goto and told me I shouldn't be using it.
VB.Net did away with Gotos and did the try/catch borrowed from Java to catch errors.
I remember learning Ada in 1989 and it used Goto statements as well. Modern Ada avoids Goto statements.
Programming without using Goto is harder and in some cases needs more lines of code.
There was never any real evidence that Goto was harmful, as the article states people accepted it was harmful without any proof. The decisions to not use Goto was decided by managers with no real world programming experience.
Dijsktra was not arguing against GOTO per se, but rather against unstructured programming.
Using GOTO to implement structured programming constructs that did not exist in the language (e.g. JMP in asm) is fine.
[1]: http://www.cs.utexas.edu/users/EWD/ewd10xx/EWD1009.PDF
[2]: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EW... (transcription)
Even keeping in mind that it was written with tongue in cheek, Mr Dijkstra does sound like a bit of a jerk in this paper. Also, I think that this response actually validates Rubin's thesis: Dijkstra points to a number of bugs in the second and third versions of the program (i.e., those without GOTO), proving that the GOTO-less version is not only shorter, but easier to get right.
In all seriousness: only just barely. I entered the undergraduate C.S. program at the U. of Kansas in 1983. The faculty were constantly saying, "We're doing structured programming now!" -- as if they weren't quite convinced yet, and needed to remind themselves.
I think this letter does correctly point out that, while simple selection & iteration constructs are sufficient to do anything we want, concise, readable code requires more. And so now we have -- yes -- return, and also break, exceptions, etc. (I'm rather surprised that the idea of a multi-level break, which has been proposed for more than one PL, has never really caught on.)
P.S. Perhaps we could title your comment " 'GOTO Considered Harmful' Considered Harmful" Considered Harmful.
Imagine the authors horror had he witnessed the use of properties in modern object oriented languages! Of course, properties are almost always trivial for an optimizing compiler, or a JITC, to inline, and inlining is the mother of all optimizations.
https://github.com/golang/go/blob/master/src/strconv/atoi.go...
https://github.com/reyk/httpd/blob/master/httpd/httpd.c#L548
Goto can be very useful when used carefully, most often for a "cleanup" block, as used in the example above. It's especially common in C where the memory needs to be freed before exiting.
longjmp(BACK_TO_MAMA,1);
Never used this though.
(I would not be opposed to making the inner and outer loops separate functions with returns, either, though)
What the author said was true at the time, but has since been dealt with by having richer control constructs for goto-less ("jump anywhere") programming.
https://github.com/torvalds/linux/search?utf8=%E2%9C%93&q=go...