top | item 46302358

(no title)

atrettel | 2 months ago

The article did not discuss this, but to me, one of the bigger differences between Fortran and more modern languages is the difference between functions and subroutines. Yes, they are not synonyms in Fortran and serve different purposes. I think this would trip up more people initially than the clunky syntax.

It is also a bit funny that the author complains about older Fortran programs requiring SCREAMING_CASE, when if anything this is an improvement over previous and current practices. Too many Fortran codes have overly terse variable names that often were just single characters or impenetrable abbreviations for obscure terms. I have had to create cheat sheets for each program to figure out what each variable was.

Sun Microsystems had a great quote about this back in the day [1]:

> Consistently separating words by spaces became a general custom about the tenth century A.D., and lasted until about 1957, when FORTRAN 77 abandoned the practice.

[1] https://docs.oracle.com/cd/E19957-01/802-2998/802-2998.pdf

discuss

order

Luminary099|2 months ago

Huh, I remember actually being taught this at school, but they never bothered to give (or I never bothered to remember) an example of a programming language that actually named void functions differently or indeed why it couldn't just be a void function. Looking at it now, it seems to be a difference inherited from mathematics, which would also explain why it's in Fortran too.

adrian_b|2 months ago

The main difference between functions and subroutines in Fortran and other ancient programming languages is not the fact that subroutines do not have a return value.

The functions of Fortran are what would be called pure functions in C (which can be marked as such with compilers that support C language extensions, like gcc).

The pure functions cannot modify any of their arguments or any global variable, and they must be idempotent, which is important in program optimization.

pklausler|2 months ago

Spaces don't matter in fixed-form Fortran source files, so I don't get that at all. And case doesn't matter in either source form.

atrettel|2 months ago

Yes, sorry for the confusion. To be clear, the quote is directly about spaces not being significant in the source code in general, but I was commenting more about how this mindset affects variable names in practice. At least in my experience, many codes would benefit from variables names that use underscores.

IAmBroom|2 months ago

What practical difference ever existed, beyond the fact that a subroutine does not return a value? AFAIK variable scope was handled identically. Recursion was likewise identical (forbidden originally).

adrian_b|2 months ago

The very important difference is that what are called functions in Fortran are called pure functions in other languages, i.e. functions that do not modify their arguments or global variables and which are idempotent, helping program optimization.

This means that Fortran functions are functions in the mathematical sense. In most early programming languages "functions" were functions in the mathematical sense, while other kinds of subprograms were named procedures or subroutines. The use of the term "function" for any kind of procedure has been popularized mainly by the C language, even if there were earlier languages where all procedures could return a value and even where any program statement was an expression, starting with LISP.

Many C/C++ compilers, e.g. gcc, support language extensions allowing functions to be marked as pure. This is always recommended where applicable, for better program optimization.

This difference is much more important than the fact that subroutines do not return a value.

Many of the "functions" of C/C++ must be written as subroutines in Fortran, with an extra argument for the result, but because they modify some arguments or global variables, not because they were written as "void" functions in C/C++.

semi-extrinsic|2 months ago

Functions return a value, subroutines do not. So functions can, at the whim of the compiler, cause an extra copy.

Style wise, many prefer to reserve functions for things that resemble mathematical functions (i.e. only intent(in) and pure). In some sense a little bit similar to how people tend to use lambdas in python.

atrettel|2 months ago

They are pretty similar, but they are definitely used differently. For one, you have to "call" a subroutine in one statement, but you can use multiple functions on the same statement (since they can return values). Functions (usually) do not change their arguments, but subroutines often do. In some sense, functions are closer to how mathematical functions work but subroutines are closer to labels for certain procedures.

whynotmaybe|2 months ago

> difference between functions and subroutines.

Waitaminit, is that why we have "sub" in Visual Basic ?

dhosek|2 months ago

Pascal also distinguishes between functions and subroutines (procedures)

thatjoeoverthr|2 months ago

Yes! QBasic also, IIRC.

auraham|2 months ago

I was about to mention that.

jolt42|2 months ago

I find it annoying in Java when uppercase is used because its an acronym. URL or UUID. No man, just Url/Uuid. No need to yell just because its an acronym.