5 ms·
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 sub
by atrettel 10mo 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 https://docs.oracle.com/cd/E19957-01/802-2998/802-2998.pdf
- pklausler 10mo agoSpaces 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 10mo agoYes, 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.
- whynotmaybe 10mo ago> difference between functions and subroutines. Waitaminit, is that why we have "sub" in Visual Basic ?
- thatjoeoverthr 10mo agoYes! QBasic also, IIRC.
- adzm 10mo agoit was a great improvement over GOSUB... which i probably have not thought about in forever
- dhosek 10mo agoPascal also distinguishes between functions and subroutines (procedures)
- auraham 10mo agoI was about to mention that.
- IAmBroom 10mo agoWhat 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).
- semi-extrinsic 10mo agoFunctions 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.
- adrian_b 10mo agoIn a well designed programming language, the compiler should always decide at its whim, whether input or output parameters need an extra copy or not, i.e. if they should be passed by value or by reference. The programmer must only specify the behavior of the parameters, i.e. if they are input, output or input-output parameters, like in Ada. The fact that a parameter is the result is just a matter of syntax, not of semantics. Any other output parameters should behave exactly like the result. This means that for any output parameter, like also for the result, the compiler must decide between receiving the output value in a register or passing an extra pointer on input that is the address of a memory area where the function must write the output value.
- semi-extrinsic 10mo agoFunctions, the way we use them in mathematical equations, have a particular syntax. The point of functions in Fortran is to mimic this as closely as reasonably possible (consider it is a language with a long history). Giving the user low-level control of how memory is used can be very useful for writing fast code. The compiler is not omniscient. Providing the choice is not bad language design.
- atrettel 10mo agoThey 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.
- Luminary099 10mo agoHuh, 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 10mo agoThe 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 10mo agoThis is complete misinformation and you should stop posting it. One can explicitly declare a function (or subroutine) to be PURE in Fortran, but it is not the default and never has been.
- jolt42 10mo agoI 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.