Hackaday
Porting COBOL Code And The Trouble With Ditching Domain Specific Languages

Whenever the topic is raised in popular media about porting a codebase written in an ‘antiquated’ programming language like Fortran or COBOL, very few people tend to object to this notion. After all, what could be better than ditching decades of crusty old code in a language that only your grandparents can remember as being relevant? Surely a clean and fresh rewrite in a modern language like Java, Rust, Python, Zig, or NodeJS will fix all ailments and make future maintenance a snap?
For anyone who has ever had to actually port large codebases or dealt with ‘legacy’ systems, their reflexive response to such announcements most likely ranges from a shaking of one’s head to mad cackling as traumatic memories come flooding back. The old idiom of “if it ain’t broke, don’t fix it”, purportedly coined in 1977 by Bert Lance, is a feeling that has been shared by countless individuals over millennia. Even worse, how can you ‘fix’ something if you do not even fully understand the problem?
In the case of languages like COBOL this is doubly true, as it is a domain specific language (DSL). This is a very different category from general purpose system programming languages like the aforementioned ‘replacements’. The suggestion of porting the DSL codebase is thus to effectively reimplement all of COBOL’s functionality, which should seem like a very poorly thought out idea to any rational mind.
Sticking To A Domain
The term ‘domain specific language’ is pretty much what it says it is, and there are many of such DSLs around, ranging from PostScript and SQL to the shader language GLSL. Although it is definitely possible to push DSLs into doing things which they were never designed for, the primary point of a DSL is to explicitly limit its functionality to that one specific domain. GLSL, for example, is based on C and could be considered to be a very restricted version of that language, which raises the question of why one should not just write shaders in C?
Similarly, Fortran (Formula translating system) was designed as a DSL targeting scientific and high-performance computation. First used in 1957, it still ranks in the top 10 of the TIOBE index, and just about any code that has to do with high-performance computation (HPC) in science and engineering will be written in Fortran or strongly relies on libraries written in Fortran. The reason for this is simple: from the beginning Fortran was designed to make such computations as easy as possible, with subsequent updates to the language standard adding updates where needed.
Fortran’s latest standard update was published in November 2023, joining the COBOL 2023 standard as two DSLs which are both still very much alive and very current today.
The strength of a DSL is often underestimated, as the whole point of a DSL is that you can teach this simpler, focused language to someone who can then become fluent in it, without requiring them to become fluent in a generic programming language and all the libraries and other luggage that entails. For those of us who already speak C, C++, or Java, it may seem appealing to write everything in that language, but not to those who have no interest in learning a whole generic language.
There are effectively two major reasons why a DSL is the better choice for said domain:
- Easy to learn and teach, because it’s a much smaller language
- Far fewer edge cases and simpler tooling
In the case of COBOL and Fortran this means only a fraction of the keywords (‘verbs’ for COBOL) to learn, and a language that’s streamlined for a specific task, whether it’s to allow a physicist to do some fluid-dynamic modelling, or a staff member at a bank or the social security offices to write a data processing application that churns through database data in order to create a nicely formatted report. Surely one could force both of these people to learn C++, Java, Rust or NodeJS, but this may backfire in many ways, the resulting code quality being one of them.
Tangentially, this is also one of the amazing things in the hardware design language (HDL) domain, where rather than using (System)Verilog or VHDL, there’s an amazing growth of alternative HDLs, many of them implemented in generic scripting and programming languages. That this prohibits any kind of skill and code sharing, and repeatedly, and often poorly, reinvents the wheel seems to be of little concern to many.
Non-Broken Code
A very nice aspect of these existing COBOL codebases is that they generally have been around for decades, during which time they have been carefully pruned, trimmed and debugged, requiring only minimal maintenance and updates while they happily keep purring along on mainframes as they process banking and government data.
One argument that has been made in favor of porting from COBOL to a generic programming language is ‘ease of maintenance’, pointing out that COBOL is supposedly very hard to read and write and thus maintaining it would be far too cumbersome.
Since it’s easy to philosophize about such matters from a position of ignorance and/or conviction, I recently decided to take up some COBOL programming from the position of both a COBOL newbie as well as an experienced C++ (and other language) developer. Cue the ‘Hello Business’ playground project.
For the tooling I used the GnuCOBOL transpiler, which converts the COBOL code to C before compiling it to a binary, but in a few weeks the GCC 15.1 release will bring a brand new COBOL frontend (gcobol) that I’m dying to try out. As language reference I used a combination of the Wikipedia entry for COBOL, the IBM ILE COBOL language reference (PDF) and the IBM COBOL Report Writer Programmer’s Manual (PDF).
My goal for this ‘Hello Business’ project was to create something that did actual practical work. I took the FileHandling.cob example from the COBOL tutorial by Armin Afazeli as starting point, which I modified and extended to read in records from a file, employees.dat, before using the standard Report Writer feature to create a report file in which the employees with their salaries are listed, with page numbering and totaling the total salary value in a report footing entry.
My impression was that although it takes a moment to learn the various divisions that the variables, files, I/O, and procedures are put into, it’s all extremely orderly and predictable. The compiler also will helpfully tell you if you did anything out of order or forgot something. While data level numbering to indicate data associations is somewhat quaint, after a while I didn’t mind at all, especially since this provides a whole range of meta information that other languages do not have.
The lack of semi-colons everywhere is nice, with only a single period indicating the end of a scope, even if it concerns an entire loop (perform). I used the modern free style form of COBOL, which removes the need to use specific columns for parts of the code, which no doubt made things a lot easier. In total it only took me a few hours to create a semi-useful COBOL application.
Would I opt to write a more extensive business application in C++ if I got put on a tight deadline? I don’t think so. If I had to do COBOL-like things in C++, I would be hunting for various libraries, get stuck up to my gills in complex configurations and be scrambling to find replacements for things like Report Writer, or be forced to write my own. Meanwhile in COBOL everything is there already, because it’s what that DSL is designed for. Replacing C++ with Java or the like wouldn’t help either, as you end up doing so much boilerplate work and dependencies wrangling.
A Modern DSL
Perhaps the funniest thing about COBOL is that since version 2002 it got a whole range of features that push it closer to generic languages like Java. Features that include object-oriented programming, bit and boolean types, heap-based memory allocation, method overloading and asynchronous messaging. Meanwhile the simple English, case-insensitive, syntax – with allowance for various spellings and acronyms – means that you can rapidly type code without adding symbol soup, and reading it is obvious even as a beginner, as the code literally does what it says it does.
True, the syntax and naming feels a bit quaint at first, but that is easily explained by the fact that when COBOL appeared on the scene, ALGOL was still highly relevant and the C programming language wasn’t even a glimmer in Dennis Ritchie’s eyes yet. If anything, COBOL has proven itself – much like Fortran and others – to be a time-tested DSL that is truly a testament to Grace Hopper and everyone else involved in its creation.
Posted in Featured, Interest, Software DevelopmentTagged cobol, FORTRAN, gnucobol
Post navigation
← Homemade VNA Delivers High-Frequency Performance On A Budget
SpaceMouse Destroyed For Science →

51 thoughts on “Porting COBOL Code And The Trouble With Ditching Domain Specific Languages”
Leave a Reply
Jetpack Comment
Please be kind and respectful to help make the comments section excellent. (Comment Policy)

Search
Search for:
Never miss a hack
Follow on facebookFollow on twitterFollow on youtubeFollow on rssContact us
Subscribe





If you missed it
- Porting COBOL Code And The Trouble With Ditching Domain Specific Languages 51 Comments
- Jenny’s (Not Quite) Daily Drivers: Raspberry Pi 1 37 Comments
- In 2025, The Philly Maker Faire Finds Its Groove 8 Comments
- Which Browser Should I Use In 2025? 84 Comments
- Supercon 2024: Quick High-Feature Boards With The Circuit Graver 11 Comments





Our Columns
- FLOSS Weekly Episode 829: This Machine Kills Vogons No comments
- Announcing The Hackaday Pet Hacks Contest 9 Comments
- Keebin’ With Kristina: The One With John Lennon’s Typewriter 2 Comments
- Linux Fu: Stopping A Runaway 29 Comments
- Hackaday Links: April 13, 2025 8 Comments

Never miss a hack
Follow on facebookFollow on twitterFollow on youtubeFollow on rssContact us
Copyright © 2025 | Hackaday, Hack A Day, and the Skull and Wrenches Logo are Trademarks of Hackaday.com | Privacy Policy | Terms of Service | Digital Services Act
Powered by WordPress VIP

SET TAXES EQUAL TO BASE_RATE MULTIPLIED-BY PERCENTAGE
; to this:
SET TAXES EQUAL TO BASE_RATE MULTIPLIED-BY (PERCENTAGE PLUS RATIO)
; Thanks! – PhilAgain – the above is NOT really COBOL – but it has the flavor, from what I barely recall from playing with a proprietary dialect known as DB/C (basically COBOL with some flat DB added on, insofar as I understood it at the time – decades ago).The entire codebase would be just as verbose – that was the purpose behind it; it was a plus for those who couldn’t read anything else (and trust me, the languages then were closer to assembler – or were assembler – than anything else), but could read plain English. Of course, for the actual programmers…well, it could be terrible, because you had to write out everything…but at least for many cases, the code was “self-documenting” – to an extent.Now Fortran – that was a different beast – it was used and abused for all kinds of stuff (look into what was done for early 2D and 3D graphics, circa-1968 forward to oh, 1975-ish?) – you’ll find it being used and abused for almost everything; the Cal-Comp graphics plotting standard was pretty popular. There was a couple of others that were developed at universities that also proved long-lived…Oh…there were also more than a few Gerber libraries for Fortran…because you have to be able to take your Cal-Comp plots, and convert them into something to share schematics (and other things; the Gerber standard was – as far as I can tell – initially meant for interchanging of “vector” graphics – and everything was a vector graphic back then, because memory for a framebuffer was…well…expensive doesn’t even begin to describe it)…But “as designed” it was a language meant to allow easy conversion of mathematical formula into a format a computer could digest, and do it efficiently (again, era of “everything is assembly”); a language meant for scientists and engineers (and be easily readable by humans, too). But it was “free” enough to do more general purpose things. Based on code I have read in various DTIC research reports and other things from the era, people seemed to love to “hack” with it! I haven’t found a game done in it, yet – but I did find a rudimentary flight simulator (about the same time around when Sub-Logic released it’s code in BASIC and assembly for various platforms; but this code was independent of Sub-Logic’s stuff – it was written for somebody’s thesis or something from the Naval Postgraduate school, or maybe it was something for the Air Force – I forget).Again – none of this proves COBOL or Fortran are DSLs, or were meant as such…but they were designed for particular “use-cases” and “industries” – COBOL pretty much stuck to it’s place, while Fortran “wandered” a bit, but still mostly kept to what it was meant for, formulas and calculations (and plotting/graphing of such) too…One other thought: At the time, it was a “radical thought” to think of using computers for anything that didn’t have something to do with calculations and formulas, or for business purposes (record keeping and reporting), or occasionally for industry (process control, for instance – but a lot of that was also done with analog computing – which was also a big thing; there were hybrids sold then, too)…Using a computer to control a robot? Artificial intelligence and games? Graphics? Insanity!Also, batch processing and punched cards didn’t lend themselves well to “general purpose” stuff…and who could ever own a computer…in their home…all to themselves? Heck, just look at the early microcomputer days, pre-1990-ish…All of it seems kinda insane to me now…thinking about it…thinking of when I was a kid with a home computer in the 1980s – when I had a modem, and most people didn’t even have a computer, let alone knew what “being online” meant – and that was really “late” in the game; now think about the heady days of the Homebrew Computer Club – when a lot of members didn’t have a computer, because a small one was either too expensive – or didn’t exist at all (there were a very, very few number of people in the world that had a “personal computer” – and generally, those machines had very little memory – on the order of a few 10s of bytes at best – and if you were clocking along at 50 Hz, that was a fast machine for something “homebrew” made out of junk parts from the telephone company or such)…but eventually…once the 4004 became a thing (though there were “electronic magazine projects” for “electronic desk calculators” – I found one recently in a British publication that essentially used something like 54xx series ICs, and a bunch of other discrete components, to implement the basic “ALU” needed for the calculator, and it had various “registers” for storage, and did the calculation using a diode array “ROM” that ran a “microcode” and a ring counter thing to “step thru” each “instruction” to “do the needful” – yes, it was a microcoded, ROM-only computer – it was pretty amazing to see – it was published over about a year’s time-frame in the magazine)./ok, if you made it down here, consider yourself a “Level-10000 Mage of the Order of Teal Deer”…Report comment
Likewise, will COBOL be any more difficult to understand than it is now?Report comment
gccorg++does under the covers of those wrapper scripts. Or a complex Makefile. Batch is stuff run from a command line or the equivalent ofcronand yes, many COBOL jobs use huge programs and databases, as you would expect in the large of a Bank or Insurance company. But a significant amount of the COBOL inventory talks to transaction processing software: CICS or Web CICS Interfaces or, increasingly REST APIs. XML and JSON support is in the standard. GnuCOBOL (free open source software — FOSS) has it and GCC COBOL 15.1 doesn’t yet. It is on the roadmap for 16.1 but will likely be in our packages before then for early adopters.Source code control was sloppy and software to help was expensive and primitive. That’s a pile of clerical work andgit(orhgor …).Report commentJust one note to add; I discovered a bug in the “Naval Tests” which were part of the alpha-testing for each new version of any COBOL compiler. It was decided to leave it there as correcting it meant that every single version of a COBOL compiler worldwide and still in use, would have to be retested. The bug is still there and every compiler has to add it’s own workaround. Report comment
First understand it – pray you have an experienced developer for the ‘old’ DSL on the team. If you don’t then pay for a couple seats for an LLM to take that role but check the assumptions you feed it.
Second: Design a replacement framework/architecture for the new target that is appropriate for the selected target language/environment, in support of:
Third: Don’t transliterate the code, statement for statement, attempting to keep the structure. Translate the code to an implementation that’s appropriate for the target execution language and environment.Report comment
has to handle legislation from several states, countries, whatever legal context
has to handle several edge cases inside these legislations
has to handle all the different input forms (validation etc.)
has to print out that stuff in a readable formPffff. I don’t think the problem is to port some language to another language. The challenge is to understand all the grown clutter and port it.(I would bet a little amount of beer that they do not have a single test case for any validation.)Report comment
The reason for the minimal maintenance is all the things broken by every fix.
When your coders add 3 new bugs for every fix, there is only one smart move:
Document existing bugs and workarounds.
Don’t touch anything.
Get a guard dog to bite anybody attempting to check in code.There should be a way to identify this in the process immaturity model, but it operates on another axis of disfunction.
‘Information hoarding’ and ‘obstruction process’ are characteristic of maintaining old code bases though.
They are sane insane responses to the management style invariably associated.
The only real sane response is ‘flight’.
Alternative is ‘retire in place’, but madness lies down that road.Report comment
Those that work with really awful systems, invariably start to ‘like’ them.
In an awful dysfunctional way, like horribly abused children.The crew keeping any old system running are always at least half the problem.Report comment
Cobol made you define every variable like a number field on a report.
BCD internally.
Pic statements. (Shudder. Also reminded of DataFlex…the most awful language ever! COBOL programmer got drunk AF with GWBasic programmer. Woke up with sore, crabs. DataFlex shit out 9 months later. Arrays missing.)I did lots of math using floats.
Your first statement missing ‘financial’.
Even there floats can be the right type.
Do option math in fixed point.Report comment