comp.lang.ada
 help / color / mirror / Atom feed
From: "Chad R. Meiners" <crmeiners@hotmail.com>
Subject: Re: checking a loop execution
Date: 2000/04/22
Date: 2000-04-22T00:00:00+00:00	[thread overview]
Message-ID: <3901fc68.0@silver.truman.edu> (raw)
In-Reply-To: 8do7b2$p8h$1@nnrp1.deja.com


"Robert Dewar" <robert_dewar@my-deja.com> wrote in message
news:8do7b2$p8h$1@nnrp1.deja.com...
> In article <38fece05.0@silver.truman.edu>,
>   "chad" <crmeiners@hotmail.com> wrote:
> > The following code does what you want:
> >
> >   declare
> >       Index      : Integer := 1;
> >       Interupted : Boolean := False;
> >   begin
> >
> >       loop
> >
> >           Interupted := <Condition>;
>
> I find the use of boolean variables like this annoying
> obfuscation in many cases. I would not mind at all using
> a goto for this special case of a loop with multiple exits.
> Some languages have a special construct for this, but if
> this is lacking, then really the goto is as clear as anything
> and avoids duplicating a test.

hmm...  Would you care to explain how this variable is annoyingly
obfuscating, or do you prefer to make unsupported assertions ;)  I did
consider using gotos, but I didn't think that this problem warranted them.

> Yes, I know some people get the heebie-jeebies when they
> see a goto, but just remember you weren't born this way,
> it is learned behavior, and it can be unlearned. Almost
> every style rule should be considered as a guide, and the
> really skilled programmer is one who does not have to rely
> on absolute rules like "Never use a goto", and instead knows
> enough to discriminate.

My first programming language was BASIC.  So please do not assume that I
dislike gotos in fact I actually agree with you that the above rule is silly
and that style rules are guidelines.  Perhaps you should have politely asked
why I decided not to use gotos.  It would have been more constructive and
better received.  (Remember this isn't necessary my advice it could have
been your mother's)

> Code like
>
> for J in 1.. 10 loop
>    if Condition then goto Loop_Interrupted;
>    ....
> end loop;
>
> --  Here if loop ends normally
>
> ...
> return;
>
> --  Here if loop ends abnormally
>
> <<Loop_Interrupted>>
> ...
> return;
>
>
> reads quite clearly to me, and I would be surprised and a
> bit puzzled by any programmer to whom it did NOT read
> clearly.

Yes provided that the loop is short and uncomplicated (which in this case it
is ;).  However, the use of a for loop sets up the expectation that the loop
is going to execute a predetermined amount of times.  Therefore putting
other exit conditions inside of a for loop is misleading to the reader.  A
while loop also carries similar expectations, but a general loop construct
does set up such expectations, and thus the reader expects that they are
going to be defined inside the loop.  This is why my code is constructed as
it is.  I wanted the exit conditions to be precisely and clearly defined.
Since both the for and while loop carried unwanted expectation I didn't use
them.  Now I guess I should explain why I used and exit when and an if block
instead of the gotos that Dr. Dewar seems so fond of advocating.  First,
exits are what you normally use to exit out of a loop.  Second, gotos tend
to set off warning bells when a reader encounters them, and I didn't feel
that the code was doing anything that deserved to alarm the reader.  Third,
I figured that the compiler would remove the additional check since
Interrupted remains constant after the loop has been exited.

><SNIP>

> I think I mentioned before running into a COBOL programmer
> who hated gotos but had no hesitation in writing a STOP RUN
> verb deeply embedded into his program :-)

Although I am not familiar with COBOL's syntax, if STOP RUN is an something
like BREAK or STOP then it makes perfect sense to use it instead of a goto
THE_END equivalent, since label names don't have to tell the truth.  ( I
know the joke is that the programmer didn't believe the two were equivalent
;)

> Sometimes I have seen goto allergic people do this in Ada
> too, interfacing the exit routine!

Find it amusing that you attach these jokes in reply to my posting given
that they bear no relevance what so ever since I am clearly not allergic to
gotos.  So clearly there is no reason to go on a crusade.






  reply	other threads:[~2000-04-22  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-19  0:00 checking a loop execution pumilia
2000-04-19  0:00 ` DuckE
2000-04-20  0:00 ` chad
2000-04-21  0:00   ` Robert Dewar
2000-04-21  0:00   ` Robert Dewar
2000-04-22  0:00     ` Chad R. Meiners [this message]
2000-04-23  0:00       ` Robert Dewar
2000-04-24  0:00         ` Ehud Lamm
2000-04-24  0:00           ` Ehud Lamm
2000-04-24  0:00       ` Bill Greene
2000-04-20  0:00 ` tmoran
2000-04-20  0:00   ` Charles Hixson
2000-04-20  0:00 ` Andreas Schulz
2000-04-20  0:00 ` Geoff Bull
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox