Tales from Mainframe Modernization

https://news.ycombinator.com/rss Hits: 8
Summary

At my last workplace, I wrote transpilers (or just compilers if you prefer) from mainframe languages (COBOL, JCL, BASIC etc.) to Java (in Rust!). Legacy code is full of surprises. In the roughly 200k lines of COBOL that I had the (dis)pleasure of working with, I saw some wonderful hacks to get around the limitations of the system. Mainframes are also chock full of history. Base-10 numerics This is the first thing that stood out to me when I looked at COBOL code, a data-definition (the phrase for “variable”) in COBOL is declared like so: ,-- name | ,- type __|___ __|_ 01 HEIGHT PIC 9(3). -- --- | | | `- picture clause (keyword) `- level number That statement declares a variable called HEIGHT with type 9(3), which is shorthand for 999, which indicates “3-digit number”. The possible values for this variable are 0 to 999! Internationalisation Below is another data-definition in COBOL, declaring 3 variables: 01 FOO-PERSON. 05 FOO-NAME PIC X(5). 05 FOO-HEIGHT PIC 9(3). What that means is: FOO-PERSON: a “group” variable consisting of two other variables FOO-NAME: an alphanumeric type with 5 characters FOO-HEIGHT: a numeric type with 3 digits (remember, base 10 and not base 2) COBOL has an interesting construct called “REDEFINES”: 01 FOO-PERSON. 05 FOO-NAME PIC X(5). 05 FOO-HEIGHT PIC 9(3). 01 FOO-PERSONNE REDEFINES FOO-PERSON. 05 FOO-NOM PIC X(5). 05 FOO-TAILLE PIC 9(3). FOO-PERSON and FOO-PERSONNE refer to the same region of memory. I helped modernise a codebase that had clearly been worked on by a Spanish consultancy at some point, and they had decided to redefine all data definitions in Spanish. String parsing Here’s another fun one: 01 FOO-PERSON. 05 FOO-NAME PIC X(5). 05 FOO-HEIGHT PIC 9(3). . . . MOVE "PETER" TO FOO-NAME. MOVE 175 TO FOO-HEIGHT. *> display the entire memory region DISPLAY FOO-PERSON. *> PETER175 *> subscripting the first 7 bytes... DISPLAY FOO-PERSON (1:7) *> PETER17 So data-definitions simply describe names for regions. Which enables a clever way to...

First seen: 2025-05-22 01:23

Last seen: 2025-05-22 08:24