[comp.lang.ada] Ada and the infamous goto

billwolf@hubcap.clemson.edu (William Thomas Wolfe,2847,) (01/18/89)

From a recent article by blakemor@software.ORG.UUCP (Alex Blakemore):
>    According to John Barnes [Programming in Ada p. 61]
>      "The main reason concerns automatically generated programs ...
>      [to] transliterate (by hand or machine) a program from some other
>      language into Ada"
>      He also points out the syntax was deliberately made
>      to stick out like a sore thumb.  <<UGLY_LABEL>>

   From what I've heard, as recently as October's Tri-Ada '88,
   automatic translation is pretty well discredited as a software
   porting technique.  The Ada Adoption Handbook (Foreman and Goodenough,
   May 1987) summarizes: "language translation must be viewed as a risky,
   short-term proposition which will yield results of unknown quality.
   Redesigning and recoding the system in Ada or interfacing newly written
   Ada code with the current implementation are much preferred approaches.".

   The basic problem is that when one translates Fortran into Ada with
   an automatic translator, what one gets is Fortranized Ada, with
   (you guessed it...) gotos everywhere.  Other problems (Ada IC Newsletter,
   September 1988) include the lack of software engineering practices in
   the old code, and the fact that automatically translated programs often
   exhibit large timing changes (~ 50% of the efficiency of the old program). 

   Richard Waychoff, who participated in the development of the Fortran-to-Ada
   and COBOL-to-Ada translators which now reside in the Ada Software 
   Repository, was quoted as saying: "The code was not pretty and it was 
   not efficient... my guess is that the translators were never used
   [on the project for which they were originally built].".


From article <8901171823.AA20919@bx.sei.cmu.edu>, by Marc.Graham@SEI.CMU.EDU:
> 
> 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.

   Actually, a Boolean could be used to do this as well, but a 
   better solution would be to add a cycle statement.

> 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. 

     How about:

        INPUT_LOOP: loop

                       -- prompt the user

                       -- get the user's input

                       exit INPUT_LOOP when INPUT_OK;
   
                       -- inform user of reason input is invalid, 
                       --   or at least BEEP the user's terminal.

                    end loop;


     There really *is* a loop here...  

rjh@cs.purdue.EDU (Bob Hathaway) (01/19/89)

>
>   Speaking of the non-goto rationale behind Ada, can anyone tell me
>   why Ada has a goto statement??  (See LRM 5.9...)  The Rationale for 
>   the Design of Ada conveniently fails to discuss it.

Modula-2 doesn't have a goto statement and I've never missed it.
I recommend removing the goto in Ada also.   There is no high-order
justification and goto's complicate code generation and optimization.

Bob Hathaway
rjh@purdue.edu

sommar@enea.se (Erland Sommarskog) (01/20/89)

>Speaking of the non-goto rationale behind Ada, can anyone tell me
>why Ada has a goto statement??  (See LRM 5.9...)  The Rationale for 
>the Design of Ada conveniently fails to discuss it.

Besides automatic translation from other 3rd generation langauges
that were mentioned, we also have the case of kinds automatically
generated code which could be easier to produce. (SQL-Ada maybe?)
Thus, code that is never to be looked at or maintained. (Well,
it's probably looked at in the debugger.)

Just because it's there, you don't have to use it.
-- 
Erland Sommarskog
ENEA Data, Stockholm              This signature is not to be quoted.
sommar@enea.se