comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: No Go To's Forever!
Date: 2000/03/23
Date: 2000-03-23T00:00:00+00:00	[thread overview]
Message-ID: <tNwC4.964$q41.1034@news.pacbell.net> (raw)
In-Reply-To: 8bdbof$t19$1@nnrp1.deja.com

>Of course it is different, it does a different sequence of
  Either you disallow "a different sequence of operations",
in which case "Continue := True;" is disallowed, or you allow
irrelevant differences and thus the first of the goto-less
algorithms.  You can't have it both ways.

>Yes, but we are not talking efficiency here,
  Fine.  Sorry you brought it up.

>      J := D'first;
>       while J < D'last loop
>          if D (J) >= D (J + 1) then   -- sorted so far
>             J := J+1;                 -- continue
>          else
>             Swap (D (J), D (J + 1));  -- out of order, move item
>             J := D'first;             -- and start over
>          end if;
>       end loop;
>
> The objection here is again to the duplicated code. You have to
> study this to see that the two assignments to J are identical.
  Huh?  Do you mean the two places it does a "J := D'first;"?
Hardly what I'd call an obscure statement.

>but you must see that it is interesting that your only solutions
>so far involve code duplication to get rid of the goto.
  Yes, gotos allow you to reuse arbitrary segments of code.
I don't think that's necessarily a good thing.

> We always prefer for loops to while loops since they lead to a
> much clearer notion of total correctness.
  A maintenance programmer, on first glance, will probably see
the For 1 ..  N-1 and think "Oh, we're doing something N-1
times", which of course is false.  On second glance he'll notice
the label and realize he needs to study the code further to
figure out the exit condition.  A While both raises a red flag
that this might take a while, and shows directly the exit
condition.  I find the latter clearer.  It's also easier to see
the kind of running time with the While loop than with the two,
nested, with the inner one aborted, loops.

> but I find your formulation really obscures the fact that we have
> two nested loops here.
  Right.  I think it's a single code sequence being iterated until
everything is in order.  It keeps trying to get all the way through
D without discovering anything out of order.  If it fails, it does
a swap and keeps trying.  You think of it as two loops, a For and
an "if ...  goto" loop.

> Replacing a for loop with a while loop with an increment is bad
> in any case.  Replacing it with a while loop that plays games
> with the control variable to obtain the effect of two nested
> loops expressed with one loop at the syntactic level is really
> quite nasty.
  A While loop by nature does not have an incremented "control
variable".  It has a condition.  It is expected that the actions
inside will bring about a state of affairs where that condition
is true.  This may involve incrementing variables, setting them
to D'first, or anything else.

> I am always amazed by the extent to which people are willing to
> go in writing obscure code to avoid gotos; A triumph of form over
> substance :-)
  I don't think either of the goto-less versions was at all
obscure.  I do think the goto version requires more study to
understand what is going on and thus is more obscure.  It also
requires examination of the rest of the code to see if there are
any other gotos to the label.  I prefer the original, shorter,
goto-less version, but if the exact same sequence of operations
is also required, the second version satisfies.




  parent reply	other threads:[~2000-03-23  0:00 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-21  0:00 No Go To's Forever! Bill Dale
2000-03-21  0:00 ` David Starner
2000-03-21  0:00   ` Bill Dale
2000-03-22  0:00     ` Robert Dewar
2000-03-22  0:00   ` Robert Dewar
2000-03-22  0:00   ` Robert Dewar
2000-03-22  0:00     ` Roger Barnett
2000-03-22  0:00       ` Charles Hixson
2000-03-22  0:00     ` Robert A Duff
2000-03-22  0:00     ` Paul Graham
2000-03-22  0:00       ` Robert Dewar
2000-03-22  0:00         ` Paul Graham
2000-03-23  0:00           ` Robert Dewar
2000-03-23  0:00             ` Ted Dennison
2000-03-23  0:00               ` Larry Kilgallen
2000-03-23  0:00               ` Paul Graham
2000-03-23  0:00                 ` Robert Dewar
2000-03-23  0:00               ` Robert Dewar
2000-03-22  0:00         ` Brian Rogoff
2000-03-22  0:00           ` Ted Dennison
2000-03-22  0:00             ` Michael P. Walsh
2000-03-23  0:00           ` Robert Dewar
2000-03-22  0:00         ` Michael P. Walsh
2000-03-22  0:00           ` Charles Hixson
2000-04-06  0:00             ` Wes Groleau
2000-04-07  0:00               ` Charles Hixson
2000-03-21  0:00 ` Charles Hixson
2000-03-21  0:00   ` Robert Dewar
2000-03-21  0:00     ` Michael P. Walsh
2000-03-21  0:00       ` Andrew Berg
2000-03-22  0:00         ` Wes Groleau
2000-03-22  0:00           ` No Go To's Forever! (I'm sorry I spoke...) dis90072
2000-03-23  0:00             ` tmoran
2000-03-23  0:00               ` Larry Kilgallen
2000-03-22  0:00     ` No Go To's Forever! Ken Garlington
2000-03-22  0:00       ` Marin D. Condic
2000-03-22  0:00         ` Roger Barnett
2000-03-22  0:00           ` Larry Kilgallen
2000-03-23  0:00             ` Robert Dewar
2000-03-23  0:00         ` Keith Thompson
2000-03-24  0:00           ` Marin D. Condic
2000-03-24  0:00           ` Ted Dennison
2000-03-27  0:00             ` Keith Thompson
2000-03-28  0:00               ` Come From Forever! (was: No Go To's Forever!) Ted Dennison
2000-03-29  0:00                 ` Keith Thompson
2000-03-25  0:00           ` No Go To's Forever! Richard D Riehle
2000-03-21  0:00   ` Gautier
2000-03-22  0:00   ` Tim Gahnström
2000-03-21  0:00     ` David Starner
2000-03-22  0:00     ` tmoran
2000-03-22  0:00       ` Robert Dewar
2000-03-22  0:00         ` tmoran
2000-03-23  0:00           ` Robert Dewar
2000-03-23  0:00             ` tmoran
2000-03-23  0:00               ` Robert Dewar
2000-03-23  0:00                 ` Jeff Carter
2000-03-24  0:00                   ` Robert Dewar
2000-03-23  0:00                 ` tmoran [this message]
2000-03-24  0:00                   ` Robert Dewar
2000-03-24  0:00                     ` Robert Dewar
2000-04-16  0:00                     ` Kenneth Almquist
2000-04-17  0:00                       ` Robert Dewar
2000-04-18  0:00                         ` Dale Stanbrough
2000-04-18  0:00                           ` Robert Dewar
2000-04-18  0:00                           ` David Starner
2000-04-17  0:00                       ` Robert Dewar
2000-03-29  0:00                 ` Martin Dowie
2000-03-29  0:00                   ` Robert Dewar
2000-03-29  0:00                   ` Robert Dewar
2000-03-29  0:00                   ` Florian Weimer
2000-03-29  0:00                     ` Robert Dewar
2000-03-30  0:00                       ` Robert A Duff
2000-04-01  0:00                         ` Robert Dewar
2000-04-01  0:00                           ` Robert A Duff
2000-04-02  0:00                             ` Robert Dewar
2000-04-21  0:00                       ` Florian Weimer
2000-04-21  0:00                         ` Robert Dewar
2000-03-24  0:00         ` tmoran
2000-03-22  0:00     ` Robert Dewar
2000-03-22  0:00       ` Ken Garlington
2000-03-21  0:00         ` Keith Thompson
2000-03-22  0:00         ` Robert Dewar
2000-03-23  0:00           ` Ken Garlington
2000-03-22  0:00         ` Robert Dewar
2000-03-23  0:00       ` Tim Gahnstr�m
2000-03-22  0:00 ` Pascal Obry
2000-03-22  0:00 ` Marin D. Condic
2000-03-22  0:00   ` Robert Dewar
2000-03-22  0:00   ` Robert Dewar
2000-03-22  0:00   ` Robert Dewar
2000-03-22  0:00     ` Jon S Anthony
2000-03-22  0:00       ` Roger Barnett
2000-03-23  0:00         ` Robert Dewar
2000-03-23  0:00           ` Roger Barnett
2000-03-24  0:00             ` Robert Dewar
2000-03-23  0:00       ` Robert Dewar
2000-03-22  0:00         ` Jon S Anthony
2000-03-23  0:00   ` Chris Morgan
2000-03-22  0:00 ` Richard D Riehle
2000-03-23  0:00   ` Jeff Carter
2000-03-23  0:00     ` Michael P. Walsh
2000-03-23  0:00       ` Brian Rogoff
2000-03-23  0:00     ` Robert Dewar
     [not found] ` <01bf9436$9c054880$2c5101be@bthomas4663>
2000-03-23  0:00   ` Robert Dewar
2000-03-23  0:00   ` Ken Garlington
replies disabled

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