COBOL idioms and clean code
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.
The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev