On Fri, 18 Jun 2021, at 17:50, Bob Bridges wrote:
> I've never written in one of those languages, but while I don't feel 
> that way about DO and END -- maybe because they're text, not 
> one-character symbols -- I kind of see what you're getting at.  By 
> habit, though, I'd probably write it the same way I do it in REXX:
> 
>    if (something == 10) {
>      run some stuff;
>      run more stuff;}

That's a bad idea.  The trailing "}" is extremely easy to miss out, or
not see.  Someone could copy the two action lines elsewhere or 
copy others from elsewhere into this grouping and accidentally 
bring a line with a "}" in it by mistake.

If one's comparing two versions of a piece of code, the compare 
logic (diff, or whatever) is far more likely to match a line which 
contains just an "end" or "}" properly in both files, and then show
the differences in the action lines.

It's also easier for future maintenance not to have the "}" at the 
end of a line, as it may need to be moved elsewhere.


Forty years ago I used a variant of Algol which used a syntactic
difference to indicate different types of if statements.  You could
have

  if condition do thing ;

  if condition do { this; that; other } ;

  if condition then thing1 else thing2 ;

  if condition then {thinga ; thingb; thingc } else ...

that is, { and } were used only (as a shorthand for "begin" and 
"end") for grouping multiple statements into a single clause, and

if ... do 

signalled to the compiler that there was no "else" coming along 
in future, whereas 

if ... then 

meant that there had to be an "else" that matched this if, later on.

It made the compiler simpler to write, and solved the problem of 
a compiler having to decide on nested ifs which one an else 
belonged to (the "hanging else" problem - usually solved by 
assuming an else belongs to the most recent if).  

Because it made clear whether an else would be expected it also
made code a lot easier for humans to read because you knew 
right at the start when you saw the "if" line whether there'd be an
"else" further on.
 
-- 
Jeremy Nicoll - my opinions are my own.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to