Hmmm, I would suppose that, as of today, we are all writing in structured programming, aren't we?

The old debate on GOTOs is gone and has been away for quite a while, isn't it?

I have written quite a number of programs packed with GOTOs or equivalent statements in various languages (Fortran, Basic, Assembler, etc.) in the 1980s. Thanks God, N. Wirth and E. Dijstra, among others, have given us better constructs, such as if/then/else, case or switch, etc.

Having said that, I am using very commonly a proprietary language where the GOTO is the only exit forward. I have a procedure looping on the records of a database, I am making a number of tests on the current record, but my only way to say that this record is not one that I want to process is to say something like "goto next record". I do not have a 'next' or a 'continue' instruction or whatever, so the goto is my favorite.

Consider the following pseudo code:

if (a != b) if (a != c) if (a != d) if (a != e) f = a else ... endif endif endif

This is just a short example, I have seen examples with about ten level of if/then/else nesting. This is becoming difficult to follow. Compare to:

next if a == b; next if a == c; next if a == d; ...

Isn't the second version clearer?

In the proprietary language I am talking about, I have to do something like this:

if (a == b) goto next_record; if (a == c) goto next_record; ...

Should I faint on the GOTO word?

I do not think so. In such a case, I claim that GOTOs make the code much cleaner and much more readable that a strict adhesion to some idealized version of structured programing.

The authors ot the Camel Book say somewhere (if I remember correctly) that progamming is often a matter of descending a decision tree. There is nothing wrong, in their view, with using the next, continue and last keywords to shortcircuit annoying cases and get right to the interesting stuff.

Having said all that, it is of course up to you to decide how far you want to go challenging some principles that we have all been nurtured with.

Well, my two cents worth...


In reply to Re: Unconventional exit from while loop by Laurent_R
in thread Unconventional exit from while loop by hdb

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.