Hi GrandFather,

I upvoted your very good post, but I have to disagree somewhat with this:

Named blocks used to be the GOTO answer for this sort of problem, but goto is frowned on because it tends to obscure code flow.
Many years ago, I had a CS professor who (mildly) criticized my code (but still gave me a good mark) because I was using constructs similar to next, last and return to exit early from a loop because, he claimed, this was akin to (an evil) GOTO. I disagreed moderately with him at the time, and, with three decades of experience in between, I still disagree, much more strongly, with this view today.

In the debate that followed the famous Go to statement considered harmful article (https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf) by E. Dijkstra (with a title staged to polemicize chosen by N. Wirth), Donald Knuth (Structured Programming with go to Statements, http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf) argued for a more balanced view making (among other things) a distinction between goto forward and goto backward (I'm simplifying quite a bit). Goto backward, he admitted, are often bad because they pave the way for spaghetti code. But goto forward, he said, make sense in many situations. Most of us don't use goto nowadays (at least not in Perl, except possibly and quite rarely for the different goto &NAME form), but next and last statements were invented as a form of healthy structured programming goto forward to exit early from a loop. I agree with Knuth on that (I'm just saying that to state what I think, but, of course, I realize that no one cares about what I think about D. Knuth's arguments on the subject).

In brief, I really don't think that named blocks tend to obscure code flow (contrary to goto statements). I think they usually are a very natural and clean way to exit early from a loop and that alternatives often tend to be more complicated.


In reply to Re^2: returning to the outer loop by Laurent_R
in thread returning to the outer loop by Anonymous Monk

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.