Negated wrote:You need goto to get to good code.
Heh. I've seen a couple of cases where I could make a chunk of code smaller, faster and much more readable by the introduction of one or two judicious goto
statements. It was fun watching how flustered the more doctrinaire programmers got trying to argue that it was "bad code".
Of course, Dijkstra's original paper was more of a comment on missing language structures and problems with programmers' "culture" than it was about the moral qualities of a goto
. The above cases were when working in C (or C++, which has the same problems). When working in perl, for example, I really haven't felt the lack (though I have in python, and can't quite explain why).
I've also had a bit of fun using the anti-goto doctrine as a critical part of a proof that good code can't exist. You start with a definition of "good code" that includes "no goto statements". You then observe that, whatever language you are working in, the code must ultimately be translated to machine code before it can execute. All machine languages make heavy use of goto statements, both absolute and conditional. Therefore, by the definition, machine code can't be "good code". However, the machine code is logically equivalent to the source code, in whatever language you're using, and must therefore have exactly the same properties. So your source code, if it runs correctly, is equivalent to a specific string of machine code, which we know is "bad code" because it contains goto
s, proving that your code is also "bad code".
(I tend to consider this a distant relative of all the "all integers are interesting" joke, but it's interesting that few programmers respond to the above proof by laughing. Maybe when you disguise a joke well enough, people don't recognize it as such, and take it seriously. Anyway, I've seen people go to great lengths trying to find a hole in the above reasoning, which just might be even funnier than the "proof" itself.)