||
On 2020-03-25 12:34 AM, Seymour J Metz wrote:
It's much cleaner in PL/I than in REXX; ITERATE and LEAVE use labels rather
than control variables.
FOO: DO I=1 TO N
...
ITERATE FOO
...
END
BAR: DO I=1 TO N
...
ITERATE BAR
...
END
That's just a GOTO with a mask on!
All the anti-goto rhetoric is dogmatic BS! We all know we should use
structured constructs for loops like while/until etc. You're iterate example
is just a goto with a different name. Same with leave with labels.
What's the difference?? They are probably considered better because to name
signifies intent but the action is the same as a goto.
In systems software languages that do not support RAII goto is almost
always the best choice for error handling with cleanup code which is why
it is still widely used by (sensible) engineers.
I would challenge anybody to refactor this code without goto's.
https://github.com/eclipse/omr/blob/e9b85117d18c369108a9ddb790023103c35b4379/thread/common/omrthread.c#L246
Note that the two loops have the same control variable but the labels are
different.
--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3
________________________________________
From: IBM Mainframe Discussion List <[email protected]> on behalf of Paul
Gilmartin <[email protected]>
Sent: Tuesday, March 24, 2020 11:41 AM
To: [email protected]
Subject: Re: GOTOs (was CLIST)
(Thanks for changing the Subject:)
On Tue, 24 Mar 2020 11:19:16 -0400, Bob Bridges wrote:
There is such a thing as overdoing GOTOs, but I agree that a blanket
never-do-it rule is counter-productive. I don't often use SIGNAL in REXX,
because I find that its structured features are adequate. But in other
languages I have argued for limited GOTO use.
In COBOL, for example, it seems to me that there's a place for GOTO
TOP-OF-PARAGRAPH (to simulate ITERATE in REXX), GOTO EXIT-PARAGRAPH (to
simulate LEAVE) and GOTO END-OF-PROGRAM (for controlled abend conditions).
These don't violate structured-programming principles, they implement them. In
VBA I freely use Goto IterateSomething (putting the label just before the Next
statement). I don't think PL/1 ever needs it, but I'm glad it's there just in
case.
Even in REXX there's one missing structured ingredient: some way to leave a
~simple~ block. A SELECT comes close, but it's not perfect. Say you're
looping through a list of candidates and have to perform a number of candidates:
do jr=1 to stem.0
v0=stem.jr
if v0='' then iterate
v1=function1(v0)
if v1<5 then iterate
v2=functionv2(v1 + othervalue)
if v2=previous then iterate
say 'TRK:' v0 v1 v2
end
I almost always label ITERATE, LEAVE, and END for clarity and'
syntax error detection:
do jr=1 to stem.0
v0=stem.jr
if v0='' then iterate jr
v1=function1(v0)
if v1<5 then iterate jr
v2=functionv2(v1 + othervalue)
if v2=previous then iterate jr
say 'TRK:' v0 v1 v2
end jr
(Even though it looks more like "GOTO jr".)
That's great in a controled DO loop. But it's harder in simple block of code.
A SELECT won't do the job, because of the calculations you have to do between
the various tests. I handle it this way:
do 1
if v0='' then leave
v1=function1(v0)
if v1<5 then leave
v2=functionv2(v1+othervalue)
if v2=previous then leave
say 'TRK:' v0 v1 v2
end
Even at the cost of introducing an almost-otiose control variable:
do myBlock= 0 for 1
if v0='' then leave myBlock
v1=function1(v0)
if v1<5 then leave myBlock
v2=functionv2(v1+othervalue)
if v2=previous then leave myBlock
say 'TRK:' v0 v1 v2
end myBlock
I always suspect I'd get complaints from structured enthusiasts if they ever
saw me cheating like that. ...
Not from me. Except for not using labels.
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN