Why does COBOL have to be indented, as in, have additional spacing in each sourcefile?
Consider this code (note the additional whitespace):
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY 'Hello, world'.
STOP RUN.
A similar formatting can be seen in Fortran code:
program hello
print *, "Hello World!"
end program hello
But why do COBOL and Fortran need this whitespace? What's the reason?
Cobol no longer has to be indented. AFAIK, all most modern compilers support format free Cobol source.
The original reason was dealing with punch cards. Cobol kept the first 6 positions for a line sequence number. Column 7 was a continuation / comment / debug / form-feed. Area "A", or Columns 8-11, indicated certain special language artifacts like 01 levels, section or paragraph names, et al. Area "B", or Columns 12 - 72, was for open code. Columns 73 - 80 were for OS sequence numbers.
The two languages you mention, Cobol and Fortran, were both written before automatic parser generation existed. And they had no real prior art to draw on for good and bad ideas of how to create parse-able source text. So some of the things -- like Area "A" for special section headers -- made the task of manually writing parsers easier. Modern languages tend to use context free grammars to make parser generation simple. But that postdates Cobol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With