title: GOTO still considered harmful?
body: <p>Everyone is aware of Dijkstra's <a href="http://portal.acm.org/citation.cfm?doid=362947" rel="noreferrer">Letters to the editor: go to statement considered harmful</a> (also <a href="http://www.cs.utexas.edu/%7EEWD/transcriptions/EWD02xx/EWD215.html" rel="noreferrer">here</a> .html transcript and <a href="http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF" rel="noreferrer">here</a> .pdf) and there has been a formidable push since that time to eschew the goto statement whenever possible. While it's possible to use goto to produce unmaintainable, sprawling code, it nevertheless remains in <a href="http://msdn.microsoft.com/en-us/library/13940fs2(VS.71).aspx" rel="noreferrer">modern programming languages</a>. Even the advanced <a href="http://en.wikipedia.org/wiki/Goto#Continuations" rel="noreferrer">continuation</a> control structure in Scheme can be described as a sophisticated goto.</p>
  <p>What circumstances warrant the use of goto? When is it best to avoid?</p>
  <p>As a follow-up question: C provides a pair of functions, setjmp() and longjmp(), that provide the ability to goto not just within the current stack frame but within any of the calling frames. Should these be considered as dangerous as goto? More dangerous?</p>
  <hr />
  <p>Dijkstra himself regretted that title, for which he was not responsible. At the end of <a href="http://www.cs.utexas.edu/%7EEWD/transcriptions/EWD13xx/EWD1308.html" rel="noreferrer">EWD1308</a> (also <a href="http://www.cs.utexas.edu/%7EEWD/ewd13xx/EWD1308.PDF" rel="noreferrer">here</a> .pdf) he wrote:</p>
  <blockquote>
  <p>Finally a short story for the record.
  In 1968, the Communications of the ACM
  published a text of mine under the
  title &quot;<em>The goto statement considered
  harmful</em>&quot;, which in later years would
  be most frequently referenced,
  regrettably, however, often by authors
  who had seen no more of it than its
  title, which became a cornerstone of
  my fame by becoming a template: we
  would see all sorts of articles under
  the title &quot;X considered harmful&quot; for
  almost any X, including one titled
  &quot;Dijkstra considered harmful&quot;. But
  what had happened? I had submitted a
  paper under the title &quot;<em><strong>A case against
  the goto statement</strong></em>&quot;, which, in order
  to speed up its publication, the
  editor had changed into a &quot;letter to
  the Editor&quot;, and in the process he had
  given it a new title of his own
  invention! The editor was Niklaus
  Wirth.</p>
  </blockquote>
  <p>A well thought out classic paper about this topic, to be matched to that of Dijkstra, is <a href="http://www.clifford.at/cfun/cliffdev/p261-knuth.pdf" rel="noreferrer">Structured Programming with go to Statements</a>, by Donald E. Knuth. Reading both helps to reestablish context and a non-dogmatic understanding of the subject. In this paper, Dijkstra's opinion on this case is reported and is even more strong:</p>
  <blockquote>
  <p><em>Donald E. Knuth:</em> I believe that by presenting such a
  view I am not in fact disagreeing
  sharply with Dijkstra's ideas, since
  he recently wrote the following:
  &quot;Please don't fall into the trap of
  believing that I am terribly
  dogmatical about [the go to
  statement]. <strong>I have the uncomfortable
  feeling that others are making a
  religion out of it, as if the
  conceptual problems of programming
  could be solved by a single trick, by
  a simple form of coding discipline!</strong>&quot;</p>
  </blockquote>