In article , Martin Gregorie wrote:
> Think how much code you'd need in any other language to get the
> same print formatting as the single COBOL declaration:
>
> 05 INVOICE-TOTAL PIC "Z(4)9.99CR" BLANK WHEN ZERO.
>
> For those who don't know the COBOL: zero would produce a blank, 0.5
> becomes, " 0.50 ", -0.5 becomes " 0.50CR" and, of course 1024
> becomes " 1024.00 ".
I've never used COBOL, but I do appreciate what's happening here.
The data division in COBOL is one of the very few forward-looking
features of that language -- a declarative description of the variables
used in the program. The clever bit, from the point of view of your
example, is that this declaration included the external representation
of the variable. Not always what you want but, for the sort of thing
that COBOL got used for, occasionally very useful.
A bit of a trick question, then, really -- in any other language you'd
have to specify the format each time you wanted to print that variable,
whereas in COBOL you just say print( INVOICE-TOTAL ) (or however you
spell that in COBOL. I can't think of ANY programming language that
does this as easily as COBOL (no, not even Algol68) -- and I've
puzzling over that for a few days -- though it's easy enough in
spreadsheets.
I've just looked up how the CR thing worked ... so CR and DB (meaning
credit or debit) both apply to negative numbers, and you define which
to use depending on which side of a balance sheet you're working ...
that's the sort of warped thinking that gets accountants a bad name!
I knew a little about the data division because I spent some time as
Prolog hacker, in my youth, and the declarative nature of Prolog always
used to confuse people *except* those who'd used COBOL and managed to
draw a parallel with the data division.
--
Cheers,
Daniel.
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|