Key Takeaways — Chapter 8: Paragraph and Section Design

Core Concepts

  1. Top-down design is the foundation of structured COBOL programming. Start with the program's overall purpose in 1000-MAIN, decompose into major steps, and continue decomposing until each paragraph is small and single-purpose.

  2. Every batch program follows the IPT pattern. Initialize-Process-Terminate structures virtually every COBOL batch program. Learn it, use it, teach it.

  3. Paragraph names are the primary documentation. Verb-noun naming with hierarchical numbering communicates program structure without reading a single line of business logic.

  4. High cohesion, low coupling. Each paragraph should do one thing (cohesion) and communicate with other paragraphs through clear contracts like 88-level condition names (low coupling).

  5. Self-documenting code is not a luxury — it is a survival strategy. Programs live for decades. When a business analyst can read your paragraph names and verify correctness, you have achieved the gold standard.

Design Principles

  • The Rule of 7: No paragraph should PERFORM more than ~7 subordinate paragraphs
  • The Scroll Test: No paragraph body should exceed one screen (~25-50 lines)
  • The Single-Sentence Test: If you need "and" to describe what a paragraph does, split it
  • The Misleading Name Test: A paragraph that does more than its name implies is worse than a vaguely named paragraph

GO TO Decision Framework

Situation Recommendation
Shop bans GO TO entirely Use condition flags or inline PERFORM with EXIT PERFORM
Shop allows disciplined GO TO GO TO only to exit paragraphs within PERFORM THRU ranges
Maintaining legacy GO TO code Document the flow; refactor when opportunity arises
Backward GO TO (loop simulation) Always replace with PERFORM UNTIL
Forward GO TO across >20 lines Replace with structured alternatives

Program Design Checklist

  • [ ] 1000-MAIN follows IPT pattern
  • [ ] Hierarchical numbering: 1000s (main), 2000s (processing), 3000s (detail), 9000s (error)
  • [ ] All paragraphs use verb-noun names
  • [ ] No paragraph exceeds 50 lines
  • [ ] No nesting deeper than 3 levels within any paragraph
  • [ ] 88-level condition names for all inter-paragraph communication
  • [ ] Every EVALUATE has WHEN OTHER
  • [ ] All END-IF, END-EVALUATE, END-PERFORM used (no period-delimited conditionals)
  • [ ] Single entry, single exit for every paragraph
  • [ ] Every paragraph is PERFORMed (no dead code)

Common Anti-Patterns

Anti-Pattern Problem Fix
"God paragraph" (>100 lines) Unreadable, untestable Extract sub-paragraphs
Generic names (PROCESS, DO-IT) Intent unclear Use specific verb-noun names
Backward GO TO Creates unmaintainable loops Replace with PERFORM UNTIL
Raw value comparisons Fragile, repetitive Define 88-level condition names
Period-terminated IF Dangling ELSE risk Always use END-IF
Paragraph doing 3+ things Low cohesion Split into focused paragraphs
Flag values as coupling Tight coupling Use 88-level names as contracts