Trivial THRU Clauses

A trivial THRU clause is one which is totally useless.

Suppose, for example, that the program says:

	PERFORM 3690-SEARCH-USOC THRU 3690-EXIT.
This THRU clauses is useless, and hence trivial, if all of the following conditions apply: If a THRU clause is trivial, remove it entirely. If there is no other reference to the EXIT paragraph, remove the EXIT paragraph as well.

These transformations are safe because they do not disrupt any other instance of fall-through logic.

A Variation

One variation is slightly less trivial:
     PERFORM 3690-SEARCH-USOC THRU 3690-EXIT.
     ...
 3690-SEARCH-USOC.
*
* do stuff here
*
     GO TO 3690-EXIT.
*
 3690-EXIT.
     EXIT.
In this case you must remove not only the THRU clause but also the GO TO.

The original spaghetti code probably won't look like this. In a later stage of transformation, however, you may insert GO TOs like this in order to eliminate fall-through logic.

Warning

Removing THRU clauses is so tedious that it is tempting to take short cuts. Don't.

Before you remove a THRU clause, verify that it meets all three of the above conditions. Otherwise you'll find an unpleasant surprise sooner or later.

In particular, beware of code like the following:

	PERFORM 3690-SEARCH-USOC THRU 3960-EXIT.
This code could be a mistake, or it could be an example of a serial THRU clause. It might even be a trivial THRU clause combined with careless paragraph names. If you're not careful, though, it will slip right past your eyeballs. You'll mindlessly delete the THRU clause, possibly with unexpected consequences.
[style forum]COBOL Style Forum [spaghetti]Spaghetti code [stage]Next stage
[home]COBOL Home