From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,99222a5bd46ef3c9 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: GOTO considered necessary (reworked) Date: 1997/06/17 Message-ID: #1/1 X-Deja-AN: 250995728 References: <5nn2fm$11dk$1@prime.imagin.net> <33A6A9C4.7B87@no.such.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1997-06-17T00:00:00+00:00 List-Id: In article , Robert Dewar 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). >dp > >(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.