Hacker News new | ask | show | jobs
by waltman 3162 days ago
It’s certainly possible; after all, the GnuCOBOL compiler is written in C. A large part of every COBOL program tends to be simple move and arithmetic statements that seem like they should be easy to port. The difficulty comes with the data declarations. COBOL’s pic statements don’t just define length and whether or not they’re numeric. They also come with complex behaviors that are enforced at run time. For example, anything that’s a pic 9 is stored as a sequence of 0-padded text digits, but you can also do arithmetic on them. They work like a car odometer in that if you add 1 to a variable that’s all 9’s, the result is all 0’s. They also allow you to do arithmetic on currency amounts (like I do in the article) exactly, without having to worry about IEEE floating point round off errors. That’s another reason the banking industry likes COBOL.
1 comments

Wouldn't that just mean using functions to have the same results?
Sure. My point was just that it's more difficult than it seems. Also this would mean that lines like

add x to y giving z

become something like

cobol_add_giving(&a, &b, &c);

which is a lot less readable.