<?xml version="1.0" encoding="windows-1252"?>
<node id="1013602" title="Re: How does 'goto LABEL' search for its label?" created="2013-01-16 11:12:35" updated="2013-01-16 11:12:35">
<type id="11">
note</type>
<author id="647953">
sundialsvc4</author>
<data>
<field name="doctext">
&lt;p&gt;
And I, for one, still will go on-record as having rejected in code review &lt;em&gt;every&lt;/em&gt; piece of logic I have ever encountered (other than in profoundly specialized cases such as device-drivers and parsers) that contained a &lt;tt&gt;goto&lt;/tt&gt;. &amp;nbsp; And here&amp;rsquo;s the very-simple reason why:
&lt;/p&gt;&lt;p&gt;
&lt;blockquote&gt;The program&amp;rsquo;s internal state, at the point of the label, is solely determined by the internal state at &lt;em&gt;every&lt;/em&gt; point that &amp;ldquo;goes to&amp;rdquo; that label ... not (only) by the statements which surround it or precede it. &amp;nbsp; You can, intentionally or worse-yet &lt;u&gt;un&lt;/u&gt;intentionally, introduce an error of the most-undebuggable kind at any point in the future ... and if what you did is syntactically acceptable, the compiler won&amp;rsquo;t say a word of warning to the effect that you just planted a high explosive device with a hair-trigger underneath your foot.&lt;/blockquote&gt;
&lt;/p&gt;&lt;p&gt;
This causes the software complexity meter to spike &amp;ldquo;infinity,&amp;rdquo; and for no purpose that cannot be better-achieved in some other way. &amp;nbsp; Even the &amp;ldquo;toy&amp;rdquo; example in the OP is effectively impossible to understand ... even as-written, &lt;em&gt;and &lt;u&gt;only&lt;/u&gt; &lt;u&gt;if&lt;/u&gt; some other &lt;tt&gt;goto&lt;/tt&gt; is not later added, somewhere, anywhere, anytime.&lt;/em&gt; &amp;nbsp; (Yes, I am intentionally stretching syntactic truth slightly to make a point ...) &amp;nbsp; You have to &lt;em&gt;think&lt;/em&gt; to realize that what this logic is actually doing is &lt;tt&gt;if ($arg != 1)&lt;/tt&gt;.
&lt;/p&gt;&lt;p&gt;
The Perl language evolved a number of constructs, such as &lt;tt&gt;last &lt;i&gt;LABELNAME&lt;/i&gt;&lt;/tt&gt;, specifically to accommodate the control-constructs that do indeed occur from time to time in production programs, and to handle them in a way that still affords for efficient code-generation and pragmatic goof-detection. &amp;nbsp; But &lt;tt&gt;goto&lt;/tt&gt;, except in the edge-cases I previously mentioned, is an unnecessary bad-idea that should never be accepted in production code. &amp;nbsp; (The edge-case exceptions are not frequent-enough to justify softening the word, &amp;ldquo;never.&amp;rdquo;)
&lt;/p&gt;

</field>
<field name="root_node">
1013574</field>
<field name="parent_node">
1013574</field>
</data>
</node>
