I guess my point is that I have a reason for not wanting to do either of the "correct" ways

The general 'better known' vs 'lesser known' argument can be summarized as: if X is a problem can be solved with either construct A or B, and if A is assumed to be more widely known, then we should choose to implement using A. A reasonably fair argument. Counter examples obviously would occur when say memory or speed is crucial and B is clearly optimal with regard to these additional constraints. But we are talking about readability optimization here right?

However, I argue that this does not apply to using goto rather than continue (even if goto is indeed more known than continue). Why? Because familiarity with goto LABEL doesn't really help the reader understand the logical structure of the code.

The logical elements of the code should be mirrored in the structural elements of the code as much as possible. This means jump destinations should mesh with the boundaries of the structural elements (block boundaries), and things like next, last, and redo do so. Using goto DONE introduces a synthetic, non-structural element to delimit a logical element of the code. This places an additional mental burden on the reader who now must maintain a dangling mental reference to a goto-label because the code structure itself provides no cue about the limits of the current logical element.

Thus while using goto may relieve your readers of having to look up continue or to learn about bare-blocks and loop control statements (as per one of tilly's suggestions), it doesn't relieve them of the mental burden of understanding the logical usage of the goto in the current code.

As an aside, another alternative for the particular code example you gave would be to use the ?: operator and avoid having both an 'if' and an 'else' block:

for my $foo (@bars) { # ... do preliminary stuff # ... if ($foo =~ /baz/i ? $foo eq uc $foo: $foo ne uc $foo) { # ... do conditional stuff # ... } # ... do remaining stuff # ... }

In reply to Re: (danger) 9: Fear of Large Languages (was: "Would you use goto") by danger
in thread Would you use 'goto' here? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.