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
gcc orÂg++ does under the covers of those wrapper scripts. Or a complex Makefile. Batch is stuff run from a command line or the equivalent ofÂcron and 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 andÂgit (orÂhg or âŠ).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