When COBOL is the right choice

The pages of this group measured a handful of things that a choice between COBOL and C++ actually turns on. This one puts the results in one place and then says where each language is the better tool, including the cases where the honest answer is neither of the two extremes: COBOL is not a museum piece and C++ is not a universal replacement.

What these pages measured

QuestionWhat the run showedPage
Is money exact?COBOL COMP-3 exact by default; C++ double wrong at the equality (678.33999999999992) and a tenth of a cent short after ten million additions; C++ cents or a decimal type exact by choiceDecimal money
Can they share a file?Yes: a 37-byte record from a packed C++ struct read by COBOL and the other way round, both printing the same five linesRecords and files
Which is faster in batch?Sort and aggregate of 200,000 records: C++ 332 ms minimum, 421 ms median; COBOL 803 ms minimum, 854 ms median, about a factor of twoBatch throughput
Which formats a report better?COBOL pictures give currency, debit and suppression in the declaration; std::format gives widths and precision and this library lacks float groupingStrings and edited output
Which survives a change?Both compilers stop on a rename and both let a widened field through; the record length changed 13 to 15 and 12 to 16 bytes with no errorMaintainability
Which tooling is there?The same three gates; COBOL has -debug and no sanitizer, C++ has sanitizers and no language-level field checksTooling

Two of those results favour COBOL, two C++, and two are a draw that depends on what the program is for. That is what a fair comparison looks like, and it is why the conclusion below is a list of situations and not a winner.

When COBOL is the right choice

When C++ is the right choice

When the answer is both

The most common real answer is a mixed system, and the pages of this group show that it works at the byte level. A COBOL batch core behind a C++ or Python front end is the shape of most modernisation projects that succeed: the records are shared (page two), the money stays decimal where it is computed (page one), the heavy sort stays where it was written and measured (page three), and the new interface is written in the language the new team knows.

The C side of that shape is what the C interop lessons build: a COBOL module called from C, a shared object resolved at run time, a record passed by pointer. It is old technology and it still works, which is the point: a modernisation that keeps the working part and replaces the edges is cheaper than a rewrite, and it can be measured one step at a time.

A closing word on legacy

Legacy is not a property of a language. The C++ program of the maintainability page is twelve bytes of struct and four lines of output, and in twenty years it will be a file that nobody dares change for exactly the reasons the COBOL program is one today: no tests, no owner, and a format that other programs read. The COBOL estate is large because it was written when the work was large, not because COBOL is old.

What the language does decide is how expensive the next change is. On this group of pages, COBOL was better at money, at report text and at staying the same; C++ was better at speed, at tooling for memory and at everything that is not a batch file. A team that knows which of those it is buying is in a better position than one arguing about which language is modern, and the numbers on these pages are here so that the argument can start from measurements instead of taste.

Every number in this article comes from a run on Alpine Linux 3.24.3 (x86_64) in a Docker container with nproc 4: cobc (GnuCOBOL) 3.2.0 and g++ (Alpine 15.2.0) 15.2.0, both with -O2 unless a page says otherwise.

Article author: Arthur Isaev

Banner image