Re: “Goto statement considred harmful”
> Any statement that can cause premature exit from a basic block complicates program flow of control, both for determining things like data flow, and for a human reader studying the code.
Exiting early from a block (return, continue, break) is relatively easy to understand in terms of logic flow, in exactly the same way that an if .. else .. divides code into bits being done and bits not being done, the limits of which are _within_ the block being examined.
The problem with a label is that the logic flow may be from any number of other blocks outside the blocks being examined. These may even have a bad effect on the stack.
> then you have longjmp.
The only time that I ever had to use this was when calling a file handling subroutine (part of a COBOL system that I think you were familiar with) from a C program. The subroutine managed to screw up the stack so I had to surround the call with a routine that did a longjmp back to itself.
> Unfortunately, not always true, due to the complex semantics of PERFORM in some conforming COBOL implementations. That's why we in fact recommend always putting PERFORMed code in a separate SECTION, rather than simply making it a paragraph - SECTION has stronger control-flow requirements.
In my experience having PERFOMs of SECTIONs is always a bad thing. From the late 60s when SECTIONs were used to overlay code the PERFORM could reload the overlay which resulted in very bad performance. The _only_ reason for PERFORMing a SECTION (or worse, using THRU) is to allow the use of GO TO. If GO TO is not allowed than there is no need for any procedure label to be a SECTION. This means that certain errors can be eliminated by using grep to ensure that there are no SECTION (in PD), no GO, no THRU. By reducing the range of constructs allowed reduces the complexity of understanding the code and reduces errors (by eliminating whole classes of errors).
> But that works precisely because it becomes an idiom and a reader can expect and recognize it.
What is more easily understood is what you are used to. The problem with idioms is that they may be skipped over because a casual glance may meet expectations, but there may be a subtle error. For example in COBOL with PERFORMed SECTIONs it is typical that they have an XX-EXIT label at the end to which an early exit is GO TO XX-EXIT. I have seen code where the wrong XX was used in an error condition that very rarely happened. In particular this was to the XX-EXIT above the SECTION so the code dropped back into the section read the next record and the program continued normally. Because it was an idiom no one had bothered to check if it was correct.