From: bobduff@world.std.com (Robert A Duff)
Subject: Re: GOTO considered necessary (reworked)
Date: 1997/06/17
Date: 1997-06-17T00:00:00+00:00 [thread overview]
Message-ID: <EBxw18.LoD@world.std.com> (raw)
In-Reply-To: dewar.866578231@merv
In article <dewar.866578231@merv>, Robert Dewar <dewar@merv.cs.nyu.edu> wrote:
>Another form of this I find annoying is "a return is basically a goto,
>so don't use returns" (for example SPARK forbids the use of gotos in
>procedures).
But a return is like a goto in a lot of ways. E.g. when reading some
code from the top, you don't know whether a given loop might terminate
prematurely due to a return. And, as I've said in another posting, I've
inserted code at the end of a procedure, thinking it will always be
executed just before the procedure returns, only to find that this is
one of those unusual procedures that contains a "return;" statement.
I'd like to have a language where there was a statement "some returns
coming up soon" at the front, so I can see that easily.
Of course, for functions, Ada doesn't allow you to set the result
without doing a return. Which I've sometimes found annoying.
>I personally find returns very handy, even though I know perfectly well
>they are gotos:
>
> procedure ... is
> begin
> if condition then
> do something simple
> return;
>
> else
> LOTS MORE CODE
>
>it is very handy to read the procedure and immediately know that you
>have the whole story if condition is true, without having to see if
>there is some code following the end if.
I'm curious: Why don't you code this as:
procedure ... is
begin
if condition then
do something simple
return;
end if;
LOTS MORE CODE
? I mean, the "else" is redundant nonsense, isn't it?
>I occasionally use gotos in a similar way, almost like an exception (and
>some fanatics would insist on turning them into exceptions) -- you are
>buried deep in complex logic, and you want to say
>
>"get out, abandon all this stuff, this is not what we are looking for, go
>and do something else"
>
>occasionally a goto conveys this intention as clearly as anything :-)
I agree -- if a goto works, then it's usually better than an exception,
in a given case. Exceptions should be reserved for the case where the
"do something else" needs to be dynamically determined (by the caller,
presumably).
>\x1adp
>
>(a little quiz, why do my messages occasionally end with ^Zdp?
> I know the answer, I am just wondering if it is obvious :-) :-)
I always assumed it's because Robert Dewar uses some weird editor, and
he's sloppy about typing. No?
- Bob
P.S. "Weird editor" means "editor I'm not used to". I'm not interesting
in starting a flame war about editors.
next prev parent reply other threads:[~1997-06-17 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 ` 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-12 0:00 ` Anonymous
1997-06-12 0:00 ` Robert Dewar
1997-06-12 0:00 ` John G. Volan
1997-06-13 0:00 ` Robert A Duff
1997-06-16 0:00 ` John G. Volan
1997-06-17 0:00 ` Robert A Duff
1997-06-25 0:00 ` Van Snyder
1997-06-17 0:00 ` Robert I. Eachus
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-20 0:00 ` Robert Dewar
1997-06-21 0:00 ` Robert A Duff
1997-06-21 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-07-21 0:00 ` Shmuel (Seymour J.) Metz
1997-06-12 0:00 ` John G. Volan
1997-06-16 0:00 ` Anonymous
1997-06-13 0:00 ` Robert A Duff
1997-06-14 0:00 ` Robert Dewar
1997-06-16 0:00 ` Robert A Duff
1997-06-17 0:00 ` Spam Hater
1997-06-17 0:00 ` Robert A Duff
1997-06-19 0:00 ` Spam Hater
1997-06-17 0:00 ` Robert Dewar
1997-06-17 0:00 ` Spam Hater
1997-06-17 0:00 ` Robert A Duff [this message]
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-16 0:00 ` Spam Hater
1997-06-17 0:00 ` Robert Dewar
1997-06-17 0:00 ` Spam Hater
1997-06-14 0:00 ` Samuel Mize
1997-06-14 0:00 ` Samuel Mize
1997-06-14 0:00 ` Matthew Heaney
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