comp.lang.ada
 help / color / mirror / Atom feed
* Another reason for goto
@ 1989-01-17 18:23 Marc.Graham
  1989-01-17 23:03 ` Ada and the infamous goto William Thomas Wolfe,2847,
  1989-01-18  4:43 ` Another reason for goto William A. Bralick
  0 siblings, 2 replies; 7+ messages in thread
From: Marc.Graham @ 1989-01-17 18:23 UTC (permalink / raw)



Ada does not have a `continue' or `abandon' statement for loop
control. Such a statement is orthogonal in some sense to exit. One
uses it in the body of a loop when one wishes to terminate this
iteration of the loop and start on the next one. To simulate it, one
issues a goto a <<label>> on a null; which is the final statement in the
loop block being continued.

Also, consider the case of input editing in a situation in which, if
the input does not pass the edit, it will be reacquired until the
input is good. Without goto one writes this as

loop
   -- get input
   case input
     when good_alt_1 =>
                   . . .
                   exit;
     when good_alt_2 =>
                   . . .
                   exit;
     .
     .
     .
     when others => null;
   end case;
end loop;

Even though I do that myself, I can't help thinking that its wrong.
There really isn't a loop here, in some sense. Good input is
processed; bad input is rejected. The thing looks better as

<<get_in>>
    -- get input
    case input
     when good_alt_1 =>
                   . . .
     when good_alt_2 =>
                   . . .
     .
     .
     .
     when others => goto <<get_in>>;
   end case;

This should occupy a hair's breadth less space and consume a hare's
breath less time. More importantly, it more nearly captures the
essence of what's going on (in my opinion, which is rarely humble).

Good code is not the result of a mindless policy of goto removal; bad
code is not the result of a sensible policy of goto insertion.

Marc H. Graham                    Software Engineering Institute
marc@sei.cmu.edu                  Carnegie Mellon University
(412) 268 7784                    Pittsburgh, PA   15213
                   

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1989-01-24 16:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-01-17 18:23 Another reason for goto Marc.Graham
1989-01-17 23:03 ` Ada and the infamous goto William Thomas Wolfe,2847,
1989-01-19  1:48   ` Bob Hathaway
1989-01-18  4:43 ` Another reason for goto William A. Bralick
1989-01-18 16:11   ` Stephe Leake
1989-01-19 17:46     ` William Thomas Wolfe,2847,
1989-01-24 16:58       ` Stephe Leake

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