Date: Sat, 29 Sep 2001 16:16:58 +0100
Reply-To: John Whittington <John.W@MEDISCIENCE.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Whittington <John.W@MEDISCIENCE.CO.UK>
Subject: Re: VALUE
In-Reply-To: <E15n4S7-0006FE-00@relay1.netnames.net>
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 15:36 28/09/01 -0500, Paul Thompson wrote:
>John Whittington wrote:
>
> > At 12:19 28/09/01 -0600, Jack Hamilton wrote (in part):
> >
>Is this thread actually a defense of GOTO?
I'm a bit confused by this 'quoting' (of white space!) - but if,as is
probably the case, Paul Thompson wrote that last line, and is asking the
question of me, then, no, it's not a thread 'in defense of GOTO'. As Paul
Dorfman has already said, GOTO really does not need to be either defended
or attacked as a generalisation. It has some uses - but also, as we know,
can also be used as a means of writing very confusing code (but that is
true of almost all elements of a programming language).
>I cannot ever see any reason to use GOTO.
One of the very first things I was ever taught at university was that, in
the real world, unconditional assertions containing words like 'no',
'none', 'all', 'never', 'always' were almost always incorrect - and 'cannot
ever' comes into that category, I reckon!
>Please, can a defender provide an example of when a GOTO does something
>that cannot be done using some sensible DO construct?
Well, as above, I don't want to get labelled as a 'defender of GOTO', but
the response to this challenge obviously depends upon what one regards as a
'sensible DO construct'. Given appropriate tools in the language (e.g. DO
WHILE, DO UNTIL etc.), I think that it is probably ALWAYS, or narly always,
possible to produce *a* DO-construct equivalent of any code which used
explicit branching (wether an explicit or 'disguised' GOTO) (it may even be
possible to produce a general proof) - but whether or not what one ends up
with would be regarded by many as a 'sensible DO construct' is another matter.
Consider an example similar to that I produced in relation to a similar
discussion here recently:
do x1 = a1 to b1 ;
do x2 = a2 to b2 ;
do x3 = a3 to b3 ;
do x4 = a4 to b4 ;
do x5 = a5 to b5 ;
do x6 = a6 to b6 ;
do x7 = a7 to b7 ;
do x8 = a8 to b8 ;
<statements>
if ar(x1,x2,x3,x4,x5,x6,x7,x8) = z then goto jump;
end ;
end ;
end ;
end ;
end ;
end ;
end ;
end ;
end ;
jump: ;
Perhaps the most obvious 'DO construct equivalent' would be something like:
flag = 0 ;
do x1 = a1 to b1 while (flag=0) ;
do x2 = a2 to b2 while (flag=0) ;
do x3 = a3 to b3 while (flag=0) ;
do x4 = a4 to b4 while (flag=0) ;
do x5 = a5 to b5 while (flag=0) ;
do x6 = a6 to b6 while (flag=0) ;
do x7 = a7 to b7 while (flag=0) ;
do x8 = a8 to b8 while (flag=0) ;
<statements>
if ar(x1,x2,x3,x4,x5,x6,x7,x8) = z then flag = 1 ;
end ;
end ;
end ;
end ;
end ;
end ;
end ;
end ;
end ;
The first example, with a GOTO, seems to me to be very clear in its
intention, efficient (conditional test only in the innermost loop), and
involves less typing. The second example would also work (if I've got it
right - not tested :-) but:
(a) the intent is not so immediately obvious, at least not to me; one has
to 'think' to work out what is going on.
(b) it is less efficient in execution (conditional tests, for the WHILE
clause, are undertaken before each and every iteration of all 8 nested loops).
(c) it involves appreciably more typing (and more scope for typos),
seemingly for no gain, beyond the ability of the programmer to boast that
(s)he has not used a GOTO statement, or equivalent.
So, I guess, a 'counter challenege'. Can Paul (T), or anyone else, explain
to me why the second piece of code above is preferable to the first. I use
GOTO very very rarely, but would certainly not suggest that there was
'never' a good argument for using it.
As I said in the recent thread about 'labelled END' statements, a 'labelled
LEAVE' statement would be an alternative to GOTO in situations such as
above - but that would really be GOTO in everything but name.
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------
|