Trivial GO TOs

You can eliminate some COBOL GO TOs by simple, mindless rearrangments. Get rid of them as soon as you spot them.

For example:

 2340-PARSE-WTN.
* some code here 

     IF SYNTAX-ERROR-FOUND
        PERFORM 2850-REPORT-SYNTAX-ERROR
        GO TO 2340-EXIT.

     PERFORM 2345-ADD-WTN-TO-LIST.

 2340-EXIT.
     EXIT.
It is amazing how often some people use a GO TO when all they need is an ELSE. Change the end of this paragraph to:
     IF SYNTAX-ERROR-FOUND
        PERFORM 2850-REPORT-SYNTAX-ERROR
     ELSE
        PERFORM 2345-ADD-WTN-TO-LIST.

Characteristics of a trivial GO TO

Variations

You can easily dream up minor variations on the example. Suppose there were no PERFORM 2850-REPORT-SYNTAX-ERROR. We could replace it with a CONTINUE statement, or we could use a negative test:
     IF NOT SYNTAX-ERROR-FOUND
        PERFORM 2345-ADD-WTN-TO-LIST.
There may be multiple GO TO statements or other complications. Maybe you can find an easy rearrangement and maybe you can't. If you find yourself staring at it very long, leave it alone and come back to it later. In the early stages of the rewrite, just try to eliminate the maximum number of GO TOs with a minimum of effort.
[style forum]COBOL Style Forum [spaghetti]Spaghetti code [stage]Next stage
[home]COBOL Home