256 points · by psim1 · 7y ago · 192 comments
While decyphering the remaining logic, I discovered what I think is the most evil programming construct I've so far seen; think goto is bad? Meet MOVE NEXT SENTENCE. COBOL is traditionally written in all uppercase (and historically EBCIDIC). So what does "MOVE NEXT SENTENCE" do? It's an unconditional jump to the next period, that's right '.'. Thats right, in a language where everything looks like it's yelling at you, you have to find a little tiny period to find where execution resumes. No labels, just a tiny couple of pixel round period. Fun...
ALTER LABEL1 TO PROCEED TO LABEL2
This will cause any gotos to LABEL1 to be redirected to LABEL2.
This is worse than older Fortran's arithmetic IF[0].
Cobol was first used in computers that are equivalent to $1.5 PIC18 microcontrollers https://www.microchip.com/paramchartsearch/chart.aspx?branch...
This was the first computer with a Fortran compiler.
IF (VALUE) 10, 20, 30
The three arguments after the value are labels that the program jumps to.
The equivalent of this line in C is something like this:
if (value < 0)
{
goto 10;
}
else if (value == 0)
{
goto 20;
}
else
{
goto 30;
}
Fortran 77 added logical IFs that work like most other programing languages.#define LABEL1 LABEL2
Is there any language that can be worse than a macro and #ifdef-ridden C? I'm only half joking.
[1] https://riptutorial.com/cobol/example/19820/a-contrived-exam...
Of course, your point stands, and this has been a long standing issue for COBOL, especially since a missing or extra period is probably still syntactically correct.
I just finished refactoring a couple of COBOL programs to remove all of the periods from PD code - which is how I prefer it. Can't wait to see how it goes at code review!
https://www.ibm.com/support/knowledgecenter/en/SS6SG3_4.2.0/...
In old non-proportional fonts on old CRT screens with low resolution, "." was a pretty noticable glyph. Typewriters tend to have rather noticable periods, too.
That convention truly was a child of its time.
So I think what you said it's true: conventions are indeed children of their times.
Totally naive to COBOL here, why do you have to do it? You said you wrote some regexes for the pull and transform, why not pipe the source to a program that finds that period for you?
I'm not sure how and on which machines COBOL code is written and compiled these days but I reckon that piping it to grep, or similar tools, might simply not be an option on those machines.
Here's someone asking about doing just that:
https://serverfault.com/questions/356574/can-i-run-grep-agai...
[0] https://en.wikipedia.org/wiki/MVS#MVS/XA
(Edited to go back even further than OS/390)
The problem isn't finding the destination, its what alternately happened been source and destination.
Also, if your reading on paper, CTRL-F isn't available. You're scanning those pages by hand. When you're sitting there, highlighter and pen in hand to make annotations and point out important shit, its a problem. End up with circles around the periods and arrows point to it with comments like "this is how we got to x from y."
Edit: also if you end up at the same place regardless of the source or from multiple sources. You can't keep the code for a level to find everywhere a jump emds up there.
Wait, you never heard about exceptions?
I thought this comment was born from naivety or bias, but after reading up on it a little further, it appears that it's true or close to true for many cases.
I do COBOL mostly in OpenVMS and only tinker with IBM in the weekends but it would be cool to see how it performs under the same circumstances compared to other languages.
We run Itanium (exciting that the first OpenVMS X86 boot was recently) and when/if I can afford a house it's going to have plenty of hard toys!
Edit: googled it and they use MIPS (millions of instructions per second).
----TIMINGS (MINUTES)----- -----PAGING COUNTS----
STEPNAME PROCSTEP RC EXCP CONN TCB SRB CLOCK SERV WORKLOAD PAGE SWAP VIO SWAPS
ENDES000 00 15522 2105 0.019965 0.000636 0.1 116946 BATCH 0 0 0 0It's analogous to saying 'A 60 year old language has better compilers than younger languages.'
Which doesn't seem especially provocative.
First, it's never going to be faster than assembly on the same machine. That is not possible.
Second, I bet it's not faster than Fortran at matrix multiplication. (And anyone who tries to do matrix multiplications in COBOL should be barred from touching a keyboard for the rest of their life.)
What it may be the fastest at is certain business calculations. And it may be the fastest at them because they are traditionally carried out in fixed-point arithmetic. IIRC (and I may not), some mainframes had specific instructions/opcodes for fixed-point math. If COBOL uses those, and other languages don't, then COBOL could in fact be the fastest... at fixed-point math calculations. That's still a long way from "the fastest processing language", though.
The claim sounds like someone has mistaken their little corner of computing for the whole universe...
It seems pretty clear from context that it means for doing report generation and accounting things that COBOL is known for, not for LINPACK.
> it's never going to be faster than assembly on the same machine.
You are being unhelpfully pedantic. It is not insightful to say an optimal assembly program is going to be at least as fast as a compiler for a higher level language.
The question ‘fastest at what’ is right there in the original quote - processing. Assembly isn’t commonly considered a ‘processing language’ and in the context processing is a term of art for the kind of batch processing tasks cobol was designed for.
Even that aside, we all ‘know’ assembly is the fastest. It’s a given. Nitpicking comments like that betrays a hostile attitude and lack of generosity of spirit. We shouldn’t have to post pages if caveats and justifications and hedging for a comment like that.
Attacks like this come across as intellectual grandstanding and aren’t actually contributing anything of value.
If something went wrong during a deployment, heaven help you. One time a pair of transposed digits got through testing and code reviews and into deployment. My colleague spotted it and called the management center to hold jobs... Thirty seconds too late.
It took four days to back everything out.
It all seemed horribly complicated and brittle to me at the time. Not sorry I don't work with it any more.
Like a whole tax form is how you’d do a Hello world.
And then we ported the runtime to render web pages over a web socket and that’s when things got really interesting. 20+ MLOC of legacy apps rendering directly to the web.
It’s such a flexible language and I absolutely enjoyed working on the run time and the other guys in the company really enjoyed writing in it.
When I started gathering requirements from the city's rep who was my point of contact I asked them for any documentation they had such as use cases, functional specs etc. All they could provide was the original COBOL source code bound up in those huge 17"x14" binders; the one's that have the holes along each side from the old dot matrix printers with every other line having that faint light green background.
Well I'd never seen COBOL in my entire live and I could only look at the code for about an hour before my eyes started to bleed. Fortunately I was able to get restricted access to the system and it ended up being pretty easy to just reverse engineer the thing by mapping each green screen of the app to a corresponding web page. In the end I didn't need any original code or documentation to do the job.
I worked a contract for an android app like that: only source, no requirements, no tests, no docs. A little bit of incomplete commentary in the code. I would build it, run it, see it crash and hope the fixes I made didn't eliminate some important feature. IDK. Isn't that the way everything works now?
Even if you had the original design documents, it is very likely that the code that runs now has widely diverged from the design documents in the past 50 years.
In addition, being risk averse for this kind of code is likely a good thing. With a rewrite, the best you can hope for is to do what you are doing now without running into bugs. At worst, you have lost a lot of money and reputation and may become bankrupt. The risk/reward tends to favor "if it ain't broke, don't fix it."
And if you've already found all the bugs, and it's performant enough, why would you ever rewrite it?
Sure, there's a maintainability issue, specifically with available developer talent.
But I feel like shepherding a mature, battle-tested codebase probably is more of an ops than a dev problem.
Is it implying that if you like doing innovative programming and learning more about new languages and your craft, you must have a short attention span?
It is also rather naive if it is believed that anything other than a tiny fraction of programming in the real world is actually innovative.
I can't help but feel that even back in the days, they would have been better served by Pascal with fix point math. The only convenient features I could spot were related to working with records in files, and Pascal has that covered.
Their Cobol implementation sort of, kind of supported subroutines but they were such a pain in the ass that code was usually copy-pasted instead.
The only thing about Cobol that I just can't stand so far is the optional filler "keywords" that allows code to look sort of, kind of like natural language. That's just wrong.
My point is that if you can implement Cobol, you can implement Pascal; and your users will be better off. Cobol has no inherent qualities from my experience that makes it a better choice.
That doesn't sound like a very good reason when you pair it with the fact that:
> Most of these people, however will start their pensions in a couple of years
Incredible oversight that will either lead to some potentially very serious consequences, or some very high consultancy costs.
Technical debt is also a huge issue indeed, since focus is always on delivering new features, because that allows leadership to move to new positions. Delivering stable maintainable code/infra isn't visible.
https://werken.belastingdienst.nl/bd-update/ict-summercourse...
And now I'm doing cryptocurrency analytics. The basic unit of Bitcoin is the satoshi, and in the protocol, all transactions are denominated in satoshis. (Similarly, in ethereum, the base unit is the wei and all transactions are denominated as 256-bit words of wei.) And yet basically all exchanges are still using floats. Sometimes they quote them as strings to avoid round-off, sometimes it's double-precision, but internally, it's all just floating point math. So once again I find myself doing everything in terms of floats, even though the underlying financial instrument uses integer units of a very small denomination.
Now that there's a huge proliferation of cryptocurrencies, I wonder if we'll eventually see one that gives up on this point and defines money as IEEE 754 double-precision floating point numbers.
This isn't directly attackable, but you could potentially trick a trading algorithm into performing stupid trades by feeding it subtly inaccurate data. If you know the particular algorithm used, though, there are probably easier ways to construct adversarial inputs and trade against them. This is why virtually all trading shops keep their algorithms secret, and also slice up & mix their outgoing orders randomly so you can't observe the output of the algorithm.
Sounds like all there customers had already worked around the bugs and they didn't want to backtrack. Floating point can be horrible because not only do both sides have to use it but they have to process their calculations in the exact same way with the same order, with decimal types you will get consistent results.
Throw in some other complexities like different clients using different value precisions, different currencies having different fractional values (japan has no decimal places, a Kuwait cent is a thousandth of a dollar) combinations of those two and more, then using decimals/money types are just easier.
languages without oddities and gotchas do tend to lend themselves to stable systems
What exactly is fixed point math? The way I deal with currency is to use decimal floating point, ie 'decimal' in C#. Is fixed point simply using integers with and making your base unit cents, not dollars?
Decimal versus binary is orthogonal. A decimal fixed-point number means that N will be a power of 10, and usually clips the range such that there are fixed number of decimal digits available (e.g., between -1,000,000 and +1,000,000). A binary fixed-point number means that N will be a power of 2, and clips its range to fix the number of binary digits (e.g., between -1,048,576 and +1,048,576). Binary floating point means that the base in arithmetic is 2, whereas decimal floating point means that base in the arithmetic is 10. C#'s `decimal` type is a non-standard decimal floating point, which looks to make the mantissa be a binary range instead of a decimal range (i.e., the maximum is not 10^n - 1 for some n).
Even more curious to me is how COBOL squares as fast if it's stuck using fixed point math.
The commonwealth bank in Australia, one of the biggest four banks in the country, spent AUD$1B migrating away from COBOL.
https://increment.com/programming-languages/cobol-all-the-wa...
It's not so much something inherent to the language, but that it's what's in use and working. It was an early language so a lot of infrastructure was built on top of it over the years and it'd be very difficult and risky to change.
PERFORM 4200-COPY-ECR THRU 4200-EXIT.
http://rosettacode.org/wiki/Factorial#COBOL
or also http://rosettacode.org/wiki/FizzBuzz#COBOL
Is there a code example where Cobol shines in comparison to, say, Python?
Today’s winner is dc
> dc is the oldest surviving Unix language.
https://en.wikipedia.org/wiki/Dc_(computer_program)?oldforma...
Yes, processing (like tabulating) fixed-size records (like punch cards) with hierarchical structure. You can do that with Python's struct module but it might be more readable in COBOL.
Other than that somewhat domain specific task, no. Python has a lot more features and is a lot more general language.
They cite: https://www.share.org/blog/mainframe-matters-how-mainframes-...
https://interskill.com/ or https://interskill.co.uk/
Disclosure: I work for them.
With this kind of thing you never know when organizations move away from the technology en masse and it would be great to be in it at the time.
Now the other question is whether it makes sense to get into Cobol from a career or business perspective and I am not so sure about that...
It all ran on IBM mainframes (the size of a small car) surrounded by disks and controllers the size of refridgerators. All the hardware was kept in a glassed-in room with white-tiled raised floor. Most of the coding was done on dumb terminals, but a few applications still had punch cards.
Ah, the memories. Long live COBOL.
If anyone has any thoughts I'd appreciate it. I'm currently writing c++ software for making robots work, plus I have financial industry experience.
I am sure there's a lot of it running still, mission critical stuff, also that there are still a few teams creating new projects with it. So it is not dead by this definition. But if I'm honest, I can't name one single language that is.
So saying COBOL powers the global economy is indeed a stretch. Want to say Linux powers it? True, Intel powers it? True. COBOL... not so much. Imagine rewriting every COBOL system in the world, now change that into replacing all Intel cpus, ~~SQL~~ OracleSQL or MySQL databases or Linux kernels...
Edit: saying "SQL Databases" makes as much sense as saying "procedural programming languages", updating it to make more sense
SQL is a very high level of abstraction, to the point where the argument is a bit absurd when compared to a very concrete example of COBOL. Yes, if we had to rewrite everything that utilized SQL then it would take an incalculable amount of effort.
I feel like you're kind of hitting the nail on the head with the Linux kernel bit though -- yes we could replace all uses of the Linux kernel with one of the many alternatives available, but it would take a long time. More likely we'd see a major transition to one of the other available kernels. This is exactly the situation COBOL is in.
All this though -- and I think we're just talking about a semantic difference on the use of "%1 powers the %2". Arguably C, SQL, and Javascript provide the value to users which encourages them to spend their money which encourages further development. So okay, I think I follow where you're coming from. COBOL doesn't power the economy, it's just the most common form of infrastructure for us to extract value from the economy. That sound a bit more correct?
This book is a great overview of the economics of these kinds of situations:
That doesn't make Cobol sounds less like a fossil in any way. It will be go away eventually.
The audio version has the quotes in the voice of the original speakers (probably because this is a radio).
There is an interactive timeline custom made for the content of the article.
Other audio logs can be accessed super easily via the drop down menu.
Incredible stuff.