My first co-op job in university involved programming in COBOL.
I later learned many other languages and have never used COBOL since, but its one feature I remember (and miss) most is the CORRESPONDING
keyword.
It could be used in three ways:
MOVE CORRESPONDING INPUT_RECORD TO OUTPUT_RECORD
ADD CORRESPONDING INPUT_RECORD TO OUTPUT_RECORD
SUBTRACT CORRESPONDING INPUT_RECORD FROM OUTPUT_RECORD
The RECORDs can be considered the equivalent of a C structure or a JavaScript object:
01 INPUT_RECORD.
05 ID PIC XXXXX.
05 VALUE PIC 999V99 PACKED DECIMAL.
05 COUNT PIC 999.
05 DATE PIC …
01 OUTPUT_RECORD.
05 THING PIC XXX.
05 COUNT PIC +(3).9(2)E+99 NATIONAL. [*floating point*]
05 OTHER PIC 999.
05 VALUE PIC 999999V99.
05 MORE PIC 9999.
With a single statement, all the fields that have the same name in INPUT_RECORD
and OUTPUT_RECORD
are processed (only numeric fields are considered for ADD
and SUBTRACT
).
In this case, only VALUE
and COUNT
are processed.
The data is also converted as necessary (e.g. VALUE
could be floating point in one record and packed-decimal in the other, or strings could be different lengths and require padding).
That one line could potentially require hundreds of lines of code in other languages, and in the future, that code would have to be modified whenever fields are added or removed from either record.
The amount of coding and debugging time saved was incredible.
Why did other high-level languages written since COBOL decide not to include a similar operation?
...
operator in javascript or the**
operator in python right? $\endgroup$...
and**
don't preserve order, but you are right they don't generally convert data types $\endgroup$