Post

Early in my career I was called on to figure out what the hell was wrong with a FORTRAN program which had worked just fine for years, but when a contractor updated some formulas, it stopped working.

This post is unavailable.

They reverted to a backup and it worked, but whenever they tried to update the maths -- which were also full of weird, redundant calculations -- it stopped working again. Nobody could figure it out. It made literally zero sense. They'd change a long formula to a shorter one and everything went nuts.

Being very new and inexperienced, I took a deep breath and started at the very beginning and now you have to know something fairly specific about FORTRAN. You know in modern programming languages, your variable names are NOT ALLOWED to start with a numeral? FORTRAN doesn't have that.

1 repost29 likes

What this means is that just like you can have a variable named x in C++, you can have a variable named 7 in FORTRAN. Or, in this particular case, 3. Apparently, the original programmer got tired of typing pi. But instead of defining a variable named "pi" -- well. You can guess, can't you?

No, this programmer assigned the value of pi to the integer 3. So at various points in the code he would have (1 + 2) or (4 - 1) in the maths, because when he used 3 it was pi. And nobody knew this, so they went "what the fuck is this" and corrected the weird redundant shit and the whole thing broke

So I corrected the issue by making the variable "pi" instead of "3" and then crawling through all the formulas making sure I put pi where it belonged. To this day I often solve mysterious, difficult issues by just... starting at the beginning and making no assumptions. Lesson learned.

Who on earth thought it was a good idea to allow the use of an integer literal as a variable name!? And how the **** did the original programmer not think twice when they had to use (4 - 1)!?

It's weirder than you think. In older versions of Fortran, it was pure pass by reference, so to make that work all numeric constants were compiled as variables that contained themselves as the value. Which means if you assigned to such a constant, you changed the meaning of that constant everywhere

I'm guessing when this code was written code reviews were not a thing. There's no way any serious programmer would have approved that.

Probably a quirk of the specific compiler. This was in the late 1980s, but the code was old and ran on an IBM 300 series mainframe, which was already ancient. I recall the problem I had to fix, but not the details of the compiler version and manufacturer.

Standard FORTRAN IV & 77 did not support lower case. Variables started with a letter (A to Z). By default, numeric variables starting with I, J, K, L, M, N were assignable only to integers & the rest were assignable only to real (floating point) values. Allowing 3=3.142 must've been a compiler bug.