COBOL musing and bemusing
I've been playing with COBOL for a couple weeks. The more I play, the more I like. The advantages go beyond the proper handling of integers and decimals. COBOL's way of describing and using data structures was clearly the best and most intuitive from the start. Other languages departed from the intuitive and only recently came back to similar
power, but still without the intuitive approach.
I've been using the
GNUcobol compiler, which runs smoothly and quickly on the command line. The developers have been working together for several years, and the project is highly active.
BUT: There's one extremely basic thing missing. I was puzzled by it, and kept trying to make it work from various angles, then located a note in the GNU documentation that verifies the basic thing is missing.
This one missing function blocks everything I would want to do with COBOL.
COBOL has a built-in way to process an entire array at once, using the ALL keyword. For instance, you can take the median of TABLE1 like this:
COMPUTE MEDIAN1 = FUNCTION MEDIAN (TABLE1(ALL)).
Other languages don't have a built-in median function.
Median is the ONLY VALID STATISTIC, and it's tricky to code properly. COBOL implements the correct accounting way of taking a median, along with the correct way of finding Midrange. I use Median and Midrange often in graphics programming.
What's missing? The ALL keyword is missing. There's no way to process an entire array in one step. GNUcobol doesn't handle it, so GNUcobol can't do the things that COBOL does best.
There are several other COBOL compilers for Windows. Some are way too expensive ($25000), some are way too simple (old 16-bit progs that won't run on Win 7). I'm willing to pay for value, but not thousands. So far I haven't found Mama Bear, but I'll keep looking. (There's probably a workaround for the missing ALL, but I haven't learned it or figured it out yet.)
= = = = =
Later: Here's what I mean by intuitive. In all other languages, starting with Fortran, an array or list has a name but the things IN the array don't have names. If you define an array with 12 items, the items are just index points inside the array. If each of the 12 items has its own contents, those are just a second index.
COBOL focuses on the things IN the array, not on the array itself. Simple example with eggs in a carton.
IDENTIFICATION DIVISION.
PROGRAM-ID. EGGS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CARTON.
05 EGG OCCURS 12 TIMES.
10 YOLK PIC 9 VALUE 1.
10 ALBUMEN PIC 9 VALUE 1.
10 SHELLCOLOR PIC XXXXXXXX VALUE "WHITE".
PROCEDURE DIVISION.
MOVE 2 TO YOLK (2).
DISPLAY EGG (1).
DISPLAY EGG (2).
STOP RUN.
The carton is just a carton. The things IN it are eggs, and we make room for 12 of them. Each egg has measurable things or qualities IN the egg, which also have their own names. I decided to use the number of Yolks (normally 1 but could be 2) and the number of Albumens (always 1) and the color of the shell. I made Egg 2 a double-yolk egg.
The DISPLAY lines tell the computer to display the contents or qualities of Egg number 1 and Egg number 2.
The PIC stuff is non-intuitive but necessary in a strongly
column-oriented system like a ledger or a computer memory. PIC is a 'picture' of the columns or memory cells needed for this particular value. 9 represents any digit, and X represents an alphanumeric character. PIC 99.99 would mean a dollars and cents number like 24.36 with no overflow allowed.
Labels: Bemusement, Real World Math