# Please explain this tech geek joke

**URL:** <https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631>\
**Category:** Miscellaneous and Personal Stuff I Must Share\
**Created:** [July 2, 2024, 2:37pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631 "2024-07-02T14:37:38Z")\
**Posts on this page:** 13\
**Page:** 6

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [July 5, 2024, 9:35pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/101 "2024-07-05T21:35:57Z")

</div>

> [@DPRK](#):
>
> My impression was not that anybody here asserted that “Fortran sucks”

The closest was **Chronos** saying that FORTRAN programmers can write FORTRAN in any language. FORTRAN code has a certain style to it which is a bit antiquated these days.

The prime example of this is _Numerical Recipes in C/FORTRAN_. FORTRAN was the original, while C was the translated version. And the C code did in fact look like reformatted FORTRAN.

Among other things, C has zero-based array indexing, while FORTRAN is one-based. But with some pointer manipulation you can act as if your C code is one-based, and so that’s what they did. Ugly as heck, but that’s FORTRAN programmers for you.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [July 5, 2024, 10:09pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/102 "2024-07-05T22:09:16Z")

</div>

Just note, though, OK, in Fortran array indices start at any number you want (not necessarily 1, though that is the default), while in C they are always based at zero— seems like C is the one looking less elegant and/or antiquated in the context of that criterion. Maybe in some hypothetical algorithm it really is natural to start counting from 2 or from −1…

[which is why mechanically “translating” Fortran into C is going to be ugly; they should not have done that…]

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [July 5, 2024, 10:16pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/103 "2024-07-05T22:16:59Z")

</div>

> [@DPRK](#):
>
> Just note, though, OK, in Fortran array indices start at any number you want

Hmm, I wasn’t aware that that was configurable.

It’s easy to have n-based arrays in C. Just:

```C
#define MALLOC_N_BASED_ARRAY(type, count, N) ((type *)malloc(sizeof(type) * count) - N)
#define FREE_N_BASED_ARRAY(ptr, N) free(ptr + N)

```

Not that I’d advocate for such an approach… though really, a similar thing is done all the time. Quicksort, for instance, recursively sorts the left and right parts of an array. Instead of having to deal with an offset manually, we can just add the offset to the base pointer and then pretend that it’s zero-based.

---

<div class="post-metadata">

**Author:** ![wolfpup](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/wolfpup/32/10618_2.png) [@wolfpup](https://boards.straightdope.com/u/wolfpup)\
**Post date:** [July 5, 2024, 10:53pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/104 "2024-07-05T22:53:32Z")

</div>

> [@Cardigan](#):
>
> I asked if he worked with any older languages. He said he worked quite a bit with FORTRAN when he started in the 1960s. He called it an “elegant” language, not like the ones today. I’m guessing this was nostalgia pure and simple, as I gather among geeks here the language is not held in high regard.

FORTRAN was “elegant” in the same sense that the DEC PDP-8 was elegant, about which I waxed enthusiastic a few posts up. Both truly were elegant and clever designs, but the most important attribute creating that warm and fuzzy feeling was that they were simple enough to fully understand. I knew everything there was to know about the PDP-8, so I truly appreciated its elegance. It wasn’t hard to become familiar with the full spectrum of the FORTRAN language, and I used to pick the option to get an assembly listing and used to marvel at the assembly code it generated.

As computers and languages got more and more complex, it became impossible to know all of it inside-out, and the childlike fascination with elegance was gradually displaced by a sense of being overwhelmed by technology that was changing faster than one could keep up with.

> [@LSLGuy](#):
>
> FORTRAN was, back in the day, “elegant” in the sense that it had very few moving parts. Picture a 3-bladed pen-knife. Simple, effective, does just what it says on the label.
> 
> Conversely a modern language and its complete supporting infrastructure is more like a car factory: sprawling and loaded with lots and lots of inter-related moving parts. All of which take expertise to understand and use well. Not so simple; not so elegant.

Exactly this! Maybe the huge system had lots of elegance, but it was impossible to tell.

> [@Chronos](#):
>
> I think that the biggest problem with Fortran is not the language per se; it’s just that, because it’s so old, a lot of what was written in Fortran was written before programmers collectively figured out what constituted good programming. Someone whose first programming language was Python was probably taught right from the outset about the importance of comments (both including them at all, and what to say in them), and appropriate situations to use various sorts of flow control constructs, and so on.

I think I can confidently say that even back in Ye Olde Dayes, the importance of commenting your code was recognized by most programmers, because it was as much out of self-interest as in helping any future programmer trying to decipher the code. And FORTRAN had subroutine and function capabilities so any half-intelligent programmer could figure out how to structure his code. So FORTRAN didn’t have conditional code blocks but had to rely on simply “IF” statements and GOTOs? I’ll say again that that sort of stuff doesn’t matter much compared to how well the overall program is structured, and even more so any larger system it might be part of.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [July 5, 2024, 11:29pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/105 "2024-07-05T23:29:22Z")

</div>

A propos of all this and what Chronos was saying, your Fortran compiler must be… pretty old if it does not support syntax like `DO WHILE`. Yet it appears to be true that some people (Olde Schoole Fortran programmers) felt that this was unnecessary bloat, compromising the elegance of the language, while others (whose voice eventually won out) demanded it. See eg  
[https://dl.acm.org/doi/pdf/10.1145/155886.155888](https://dl.acm.org/doi/pdf/10.1145/155886.155888)

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [July 5, 2024, 11:45pm UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/106 "2024-07-05T23:45:39Z")

</div>

> [@DPRK](#):
>
> [which is why mechanically “translating” Fortran into C is going to be ugly; they should not have done that…]

The array indices are just one of several things. Another quirk, which is one more of style based on language limits, is variable naming. FORTRAN 77 had at most 6-character variable names. And a lot of code was itself pretty directly translated from mathematical operations, and we know how mathematicians are in love with short names. So the FFT code in _Numerical Recipes_ looks like this:

```auto
void four1(float data[], unsigned long nn, int isign)
Replaces data[1..2*nn] by its discrete Fourier transform, if isign is input as 1; or replaces
data[1..2*nn] by nn times its inverse discrete Fourier transform, if isign is input as −1.
data is a complex array of length nn or, equivalently, a real array of length 2*nn. nn MUST
be an integer power of 2 (this is not checked for!).
{
unsigned long n,mmax,m,j,istep,i;
double wtemp,wr,wpr,wpi,wi,theta; Double precision for the trigonometric recurrences.
float tempr,tempi;
n=nn << 1;
j=1;
for (i=1;i<n;i+=2) { 

```

Sorta weird that they didn’t bother putting the comments into an actual comment block. But regardless, they are in love with short names, and none are even longer than 5 characters, with most being barely decipherable, like “wpr” or “wpi.” C always supported at least 31 characters (actually more, but the ones past 31 wouldn’t necessarily be distinguishable.

---

<div class="post-metadata">

**Author:** ![SunUp](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@SunUp](https://boards.straightdope.com/u/SunUp)\
**Post date:** [July 6, 2024, 12:56am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/107 "2024-07-06T00:56:20Z")

</div>

> [@Dr.Strangelove](#):
>
> Not that I’d advocate for such an approach…

And a good thing too.

- **Pedantic\_Man** rushes in from stage left:

The C Standard specifies that any pointer may point to the first element or any element after the first of an array object allocated via static, automatic, or `malloc()` allocation, but _not_ to any element before the first or any element after the one-past-the-first element (and a pointer pointing to the latter may not be deferenced)!

- **Practical\_Programmer** walks in from stage right:

But, you know, that’s likely to work fine the way @Dr.Strangelove specified it.

- **Pedantic\_Man** bristles at this heresy:

But this may throw a segmentation violation on old UNISYS computers! Also, and more relevant, modern optimizing compilers may spot this kind of chicanery and make optimizations that can make your relevant code do the wrong thing! _Think of the children!_

- **Pragmatic\_Programmer** shrugs:

Hey, it works on my platform right now. What are you gonna do?

- Both _exeunt_

> [@Dr.Strangelove](#):
>
> though really, a similar thing is done all the time. Quicksort, for instance, recursively sorts the left and right parts of an array. Instead of having to deal with an offset manually, we can just add the offset to the base pointer and then pretend that it’s zero-based.

Which, as my dialog from above alludes to, isn’t quite the same thing, as quicksort never goes past the bounds of the allocated array, though using pointers in that fashion does make divide-and-conquer algorithms easy to express - much more so in C than in FORTRAN.

And I think that’s at least some of the reason for the rap that FORTRAN often gets in terms of “elegance” - a lot of depends on what you think is elegant. A lot of standard computer science algorithms (such as quicksort) are recursive - early FORTRAN (though IV at least) didn’t have any provision for recursion, so you couldn’t write those algorithms without converting them into an iterative form (and making them a lot less “elegant” from the CS perspective).

On the other hand, FORTRAN can assume that two arrays passed to one of its subroutines are disjoint; i.e. they do not refer to the same areas of actual memory. So a compiler can load up the array elements into a register (or bank of registers, on vector machines like the old Cray or modern SSE microprocessors) and then chug away on the algorithm without having the kind of memory traffic that the C version will require, since it has to worry about the memory areas overlapping. Someone who just wants to get their code running, and wants it to run as fast as possible, will probably consider this to be more elegant than the ability to apply Stupid Computer Science Tricks ™ to a problem - why complicate things so much?

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [July 6, 2024, 1:19am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/108 "2024-07-06T01:19:03Z")

</div>

> [@Dr.Strangelove](#):
>
> The closest was **Chronos** saying that FORTRAN programmers can write FORTRAN in any language. FORTRAN code has a certain style to it which is a bit antiquated these days.

More to the point, every language has its own certain style to it. Which is different for every language.

Aside from the unit-offset-array thing, the other feature that Fortran is most famous for is that passing values into a function is, by default, done by reference, where almost all modern languages (counting C as modern) instead pass by value. Which means that, if you don’t specifically write your function to avoid doing so, a function can change the value of its inputs. Which can get very interesting when you call a function using constants.

---

<div class="post-metadata">

**Author:** ![SunUp](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@SunUp](https://boards.straightdope.com/u/SunUp)\
**Post date:** [July 6, 2024, 1:23am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/109 "2024-07-06T01:23:12Z")

</div>

> [@Chronos](#):
>
> Which can get very interesting when you call a function using constants.

“But hey, who hasn’t given PI the value 3.5, am I right?”

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [July 6, 2024, 1:23am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/110 "2024-07-06T01:23:54Z")

</div>

> [@DPRK](#):
>
> Just note, though, OK, in Fortran array indices start at any number you want (not necessarily 1, though that is the default), while in C they are always based at zero— seems like C is the one looking less elegant and/or antiquated in the context of that criterion.

There’s an old moviei called _The Cheap Detective_. It’s a parody of the old, hard-boiled detective movies of the '40s, with Peter Falk in the Humphrey Bogart role. In one scene, a woman meets Falk in his office and introduces herself as Denise Manderley. Ah, but he notices that she has a different name on her driver’s license. She gives him a different name, but that doesn’t match the initial on her handkerchief, etc. After she’s given about half-a-dozen aliases, he finally snaps.

“You give me the runaround one more time and I’m going to slap you around this office. I don’t care what your name is any more. Just make one up, so I know what to call you!”

I think that’s why I liked C so much. I don’t care if arrays are 0-based or 1-based, just pick one and stick with it so I know what to expect! When I used to program, I wanted to spend my effort focusing on the logic of what the program was trying to do. Every moment I spent thinking about the features of the language was a distraction from what I cared about. Keep it simple.

---

<div class="post-metadata">

**Author:** ![wolfpup](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/wolfpup/32/10618_2.png) [@wolfpup](https://boards.straightdope.com/u/wolfpup)\
**Post date:** [July 6, 2024, 1:25am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/111 "2024-07-06T01:25:08Z")

</div>

> [@DPRK](#):
>
> A propos of all this and what Chronos was saying, your Fortran compiler must be… pretty old if it does not support syntax like `DO WHILE`.

The FORTRAN I was referring to was FORTRAN IV, which indeed did **not** have those structures. This was FORTRAN IV initially for the IBM 7040/7044 before I even got to college, then later FORTRAN IV for the PDP-10 (DECsystem 10). Its control structure was only an “IF” statement of the form:

> IF ( {condition} ) {statement}

If the condition was true, {statement} would be executed. It was almost always a “GO TO”.

There was no “DO WHILE”. The “DO” statement specified the end statement of the loop, a variable to iterate, the end value, and an optional iteration increment.

If FORTRAN IV is “pretty old”, then I’m pretty old. Wait! 😲

---

<div class="post-metadata">

**Author:** ![Manduck](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/manduck/32/256_2.png) [@Manduck](https://boards.straightdope.com/u/Manduck)\
**Post date:** [July 6, 2024, 1:26am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/112 "2024-07-06T01:26:13Z")

</div>

> [@Chronos](#):
>
> Which means that, if you don’t specifically write your function to avoid doing so, a function can change the value of its inputs

It also doesn’t care if the data type of the arguments match the data type of the formal parameters. This can lead to some fun bugs when, e.g., a function does floating point math on an integer value.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [July 6, 2024, 3:24am UTC](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631/113 "2024-07-06T03:24:31Z")

</div>

> [@Manduck](#):
>
> This can lead to some fun bugs when, e.g., a function does floating point math on an integer value.

In C you can write code like

```C
float f = (float)(v - 1);  
r = 1U << ((*(unsigned int*)(&f) >> 23) - 126);

```

🙂

[Previous page](https://boards.straightdope.com/t/please-explain-this-tech-geek-joke/1003631.md?page=5)
