Date: Tue, 20 Jul 2010 02:07:14 -0400
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: Is LEAVE "non-structured"?
Content-Type: text/plain; charset=ISO-8859-1
I think that "is leave non-structured" is a rather futile question.
As far as I know, it is not part of what was originally considered
structured programming. Leave was added later as it was proved
(matematically) that you cannot always program the most efficient
algorithms without a way of escaping loops. As SAS (and most other
programming languages) do not have a statement for escaping more than
one level of looping, gotos are sometimes necessary to do that.
My priorities when programming is normally maintainability first and
then efficiency. Adhering to the rules of "structured programming" is
nowhere on my list, except what well-structured programs are easier to
understand and thus to maintain. Very often, I find that programs using
leave (and the occasional goto) are more terse, simpler, and easier to
read and understand than strictly "structured" programs - and they
are also more efficient.
On Mon, 19 Jul 2010 12:46:38 -0400, Gerhard Hellriegel
>it's right that all of programming depends on something like goto's. Also
>leave is a special kind of goto. That makes it very hard to understand big
>assembler programs and that is a reason why people had the idea of
>constructing languages which do not need such constructs any more. If you
>have a look at the results of a compiled program - some compilers let you
>see what they've done - you see all that gotos (jumps) again and you are
>glad that the compiler does it all for you. In assembler you don't have
>such nice constructs, you have only branches and jumps to labels.
>I'd also say the same for leave. With a complex condition at the loop
>header it might be hard to understand what happens, but with any leaves
>it's even harder! You don't only have to understand a complex condition,
>you also have to understand additional conditions in the loop's body. I
>prefer to have it at one location. If you are working with a actual
>project, you have it all in mind. 3 weeks later, it is gone. The same, if
>you work in teams and it's necessary that someone other can read what
>you've done. That is a normal thing in big projects and mostly the
>personal which have to maintain that are from a third party. It would not
>take long to make them HATE leaves and gotos!
>On Mon, 19 Jul 2010 10:04:10 -0500, Joe Matise <snoopy369@GMAIL.COM> wrote:
>>I'd say yes, somewhat; in that I'd avoid using LEAVE if there is a simple
>>way to do so, but if it's necessary, then you use it. I've never found a
>>reason that it was necessary to use either LEAVE or GOTO, but I certainly
>>haven't encountered the majority of possible situations in SAS :)
>>I think though that the discussion has more relevance if put into context.
>>To me structured programming is about being able to read the program, from
>>start to finish, and see what it's doing. GOTOs make that extremely hard,
>>because they move you about the program. LEAVE is not as bad, in my
>>opinion, because it just exits the loop. So while I'd not use GOTO for
>>reason, I don't object to using LEAVE, despite it making this slightly
>>clear than containing the exit information entirely in the DO statement.
>>making the DO statement do what you want it to do is impossible or
>>excessively complex, and it's clearer using a LEAVE, then do it.
>>On Mon, Jul 19, 2010 at 9:09 AM, Data _null_; <email@example.com> wrote:
>>> In a reply from Robert Rosofsky in the "Combining iterative DO and
>>> UNTIL condition" where I suggested the LEAVE statement he indicated
>>> [quote]The use of the LEAVE command feels kind of "non-structured,"
>>> but I suppose I can live with that.[/quote]
>>> I use LEAVE often and sometimes prefer it to WHILE/UNTIL. I used GOTO
>>> before we had LEAVE and still use GOTO when "I think I need to".
>>> Aren't all the programming constructs are just dressed up GOTOs.
>>> So is LEAVE non-structured?