COBOL idioms and clean code
| Sentences and verbs | |
| Scope terminators | |
| Daily habits |
Sentences and verbs
A COBOL sentence is one or more verbs ending with a period. Keep one verb per sentence in new code: it makes the debugger and the reviewer agree on what happened:
ADD WS-HOURS TO WS-TOTAL-HOURS.
MOVE WS-TOTAL-HOURS TO WS-REPORT-FIELD.
Scope terminators
Scope terminators (END-IF, END-PERFORM, END-EVALUATE) make nesting explicit. With them, a period ends only the sentence it belongs to, and nested blocks cannot swallow each other:
IF WS-OK
PERFORM PROCESS-ROW
END-IF.
Daily habits
Uppercase verbs and keywords, lowercase user names. Prefix working storage with WS-, keep paragraphs short, and let the compiler check every field with DATA DIVISION declarations before PROCEDURE DIVISION uses them.
Next: Build tools: make and cobc flags
Article author: Arthur Isaev