After midnight, part 1: COBOL

Monday 18. June, 2007

This post contains nothing perverted.

My project of taking a look at different languages has progressed to COBOL. It appeared in 1959 so it’s quite old stuff. The famous Hello world in COBOL:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
PARAGRAPH-1.

DISPLAY "Hello, world.".
STOP RUN.


It’s interesting to see that every program line starts from 8th column, or at least OpenCOBOL compiler complained if they didn’t. COBOL can be very verbosive as this Wikipedia example for solving the roots of quadratic equation shows:

COMPUTE X = (-B + (B ** 2 - (4 * A * C)) **.5) / (2 * A)


or alternatively:

MULTIPLY B BY B GIVING B-SQUARED.
MULTIPLY 4 BY A GIVING FOUR-A.
MULTIPLY FOUR-A BY C GIVING FOUR-A-C.
SUBTRACT FOUR-A-C FROM B-SQUARED GIVING RESULT-1.
COMPUTE RESULT-2 = RESULT-1 ** .5.
SUBTRACT B FROM RESULT-2 GIVING NUMERATOR.
MULTIPLY 2 BY A GIVING DENOMINATOR.
DIVIDE NUMERATOR BY DENOMINATOR GIVING X.


Using of variables requires them being introduced in a dedicated DATA DIVISION. COBOL seems to have other DIVISIONS too.

This language seems to be the coolest one I have ever seen (well, so far), but it doesn’t mean that I would like to actually use it. It has over 600 keywords(?) and it’s designed for business world, so I probably wouldn’t have use for it. It has a nice name, though.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: