comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <johnvolan@sprintmail.com>
Subject: Re: GOTO considered necessary (reworked)
Date: 1997/06/12
Date: 1997-06-12T00:00:00+00:00	[thread overview]
Message-ID: <33A0840B.1B41@sprintmail.com> (raw)
In-Reply-To: dewar.866134855@merv


Robert Dewar wrote:
> 
> Jeff Carter responded to Sam's article with a typical bunch of dogmatic
> never-use-gotos stuff that smacks of the fanaticism that was popular in
> the 70's, but I would have hoped had disappeared by now.

Funny, I read the same post and didn't come away with that impression at
all. Sounded like Jeff was voicing some reasonable concerns about the
dangers of gotos and their impact on maintainability.  (In fact, Jeff
was mostly just agreeing with some counter-arguments that Sam Mize
himself enumerated.)

> Anyway Sam, take this as a vote from me that your treatment is very nice,
> and just at the right level of dont-use-goto-except-where-useful.

I agree with that philosophy, but I'd clarify it: Gotos may be used only
as a _last_ resort, after every other possible structure has been
exhaustively tried and still found to be less understandable, or
maintainable, or efficient, or whatever, than the proposed goto
solution.  But this is a very stringent requirement, and I expect it
will be very rare that a goto solution will beat out all other
alternatives.

> I particularly object to Jeff's notion that introducing miscellaneous
> boolean flags to replace structured use of gotos (like the CONTINUE)
> makes code more readable. 

Where did Jeff say anything about extra Booleans? His point seemed to be
merely that the effect of a goto can often be achieved by abstracting an
operation out as a subprogram with one or more premature return
statements, and that this may be less prone to maintenance errors than
gotos.  For instance, Sam Mize's example of insertion would clearly be
better off as a procedure:

  Items : array (Positive range Lo .. Hi) of Item_Type;
  Last  : Natural := Items'First-1;
  ...
  procedure Insert (New_Item : in Item_Type) is
  begin
    for I in Items'First .. Last loop
      if Items(I) >= New_Item then
        -- item at index I is successor for New_Item,
        -- so move items starting from I forward and
        -- insert New_Item in front of them
        Items(I+1 .. Last+1) := Items(I .. Last);
        Items(I) := New_Item;
        Last := Last + 1;
        return; -- "premature" return
      end if;
    end loop;
    -- New_Item is greater than all Items, append onto end
    Last := Last + 1;
    Items(Last) := New_Item;
  end Insert;

I would rather trust a compiler to optimize this via pragma Inline
rather than rely on manual optimization using gotos.

> Far from it in my opinion, The use of Boolean's
> to encode state that is more reasonably and clearly encoded in the program
> counter is a big mistake in my opinion, and can often severely damage
> readability in these rare cases we are talking about.

Agreed. And agreed that these cases would be rare. (So far the only case
that I find compelling are FSAs.)  But in the procedure example above,
where pray tell are the alleged extra Booleans?  Isn't the state being
encoded in the program counter, by virtue of where the return from
procedure occurs?

------------------------------------------------------------------------
Internet.Usenet.Put_Signature 
  (Name       => "John G. Volan",
   Employer   => "Texas Instruments Advanced C3I Systems, San Jose, CA",
   Work_Email => "johnv@ti.com",
   Home_Email => "johnvolan@sprintmail.com",
   Slogan     => "Ada95: World's *FIRST* International-Standard OOPL",
   Disclaimer => "My employer never defined these opinions, so using " & 
                 "them would be totally erroneous...or is that just "  &
                 "nondeterministic behavior now? :-) ");
------------------------------------------------------------------------




  reply	other threads:[~1997-06-12  0:00 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-11  0:00 GOTO considered necessary (reworked) Samuel Mize
1997-06-11  0:00 ` Bryce Bardin
1997-06-12  0:00 ` Anonymous
1997-06-12  0:00   ` Robert Dewar
1997-06-12  0:00     ` John G. Volan [this message]
1997-06-13  0:00       ` Robert A Duff
1997-06-16  0:00         ` John G. Volan
1997-06-17  0:00           ` Robert Dewar
1997-06-17  0:00             ` Robert A Duff
1997-06-18  0:00               ` Spam Hater
1997-06-20  0:00               ` Robert Dewar
1997-06-21  0:00                 ` Robert A Duff
1997-06-21  0:00                   ` Robert Dewar
1997-06-20  0:00               ` Robert Dewar
1997-06-25  0:00               ` Wolfgang Gellerich
1997-06-25  0:00                 ` Michael F Brenner
1997-06-26  0:00                   ` Wolfgang Gellerich
1997-06-25  0:00                 ` Samuel T. Harris
1997-06-19  0:00             ` Karel Th�nissen
1997-06-19  0:00               ` Karel Th�nissen
1997-06-23  0:00               ` John G. Volan
1997-06-23  0:00                 ` Spam Hater
1997-06-23  0:00                 ` Robert Dewar
1997-06-24  0:00                   ` Brian Rogoff
1997-06-25  0:00                   ` Featuritis not always bad (was re: GOTO considered necessary) Karel Th�nissen
1997-06-26  0:00                     ` Robert Dewar
1997-06-26  0:00                       ` Karel Th�nissen
1997-06-25  0:00                 ` GOTO considered necessary (reworked) Karel Th�nissen
1997-06-23  0:00             ` John G. Volan
1997-06-17  0:00           ` Robert I. Eachus
1997-06-17  0:00           ` Robert A Duff
1997-06-25  0:00             ` Van Snyder
1997-07-21  0:00           ` Shmuel (Seymour J.) Metz
1997-06-12  0:00   ` John G. Volan
1997-06-16  0:00     ` Anonymous
1997-06-12  0:00 ` Michael F Brenner
1997-06-17  0:00   ` Robert Dewar
1997-06-17  0:00     ` Robert A Duff
1997-06-20  0:00       ` Robert Dewar
1997-06-21  0:00         ` Robert A Duff
1997-06-21  0:00           ` Robert Dewar
1997-06-13  0:00 ` Robert A Duff
1997-06-14  0:00   ` Samuel Mize
1997-06-14  0:00     ` Matthew Heaney
1997-06-14  0:00   ` Samuel Mize
1997-06-14  0:00   ` Robert Dewar
1997-06-16  0:00     ` Spam Hater
1997-06-17  0:00       ` Robert Dewar
1997-06-17  0:00         ` Spam Hater
1997-06-16  0:00     ` Robert A Duff
1997-06-17  0:00       ` Spam Hater
1997-06-17  0:00         ` Robert Dewar
1997-06-17  0:00           ` Robert A Duff
1997-06-19  0:00             ` John Herro
1997-06-25  0:00               ` Function result Van Snyder
1997-06-27  0:00                 ` Jon S Anthony
1997-06-27  0:00                 ` Robert Dewar
1997-06-20  0:00             ` GOTO considered necessary (reworked) Robert Dewar
1997-06-17  0:00           ` Spam Hater
1997-06-17  0:00         ` Robert A Duff
1997-06-19  0:00           ` Spam Hater
1997-06-16  0:00 ` Anonymous
1997-06-16  0:00   ` Robert Dewar
replies disabled

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