COBOL and C++ side by side
These pages take one task at a time, write it in COBOL and in C++, build
both with the real compilers and show the two outputs next to each
other. Then they explain what differs and why: how the number is stored,
who owns the record, what the compiler checks, and what each language
costs in a batch job.
The interesting part is rarely the syntax. It is the habit that one
compiler accepts and the other refuses, and the number that one
language computes exactly and the other nearly. Every program is on its
page in full so it can be built again, and every timing is a run from
this machine with the method written beside it. The C++ lessons are in
the C++ course and the COBOL lessons in
the COBOL course.
Cent
Decimal money: double, cents and a decimal type
One invoice computed in COBOL COMP-3 and in three C++ number types, and ten million additions that end a tenth of a cent short in double.
Open →
37
Fixed-width records and files
A 37-byte record as a packed struct and as a COBOL record: C++ writes the file, COBOL reads it, then the other way round.
Open →
Sort
Batch throughput
The same sort and aggregate job over 200,000 records in both languages, five timed runs each, the milliseconds the shell measured.
Open →
Edit
Strings and edited output
Edited pictures against std::format: a currency amount, a debit with DB, a percentage, and the name that is cut at twenty characters.
Open →
Rename
Maintainability over decades
One field renamed and one field widened in each language: which of the four builds the compiler stops, and which only change the bytes.
Open →
Hour
Onboarding
The first hour of each language: a hello program, a record, and the toolchain a reader needs before the first real task.
Open →
Flag
Tooling
cobc and g++ flags side by side, syntax-only builds, -Werror, the sanitizers, and gdb on a C++ crash.
Open →
When
When COBOL is the right choice
A closing article that rests on the numbers the earlier pages measured, and says plainly where each language wins.
Open →