Live data from Hacker News

Learning Fortran (2024)

uncenter.dev

51–60 of 85 posts

Re: Learning Fortran (2024)

#51

Earlier quoted context omitted.

Yea, Fortran is nice to use for so-called "scientific" computing. It has high performance as well as some handy intrinsic functions like DOT_PRODUCT and TRANSPOSE but the best features to me are colon array slicing syntax like Python/Numpy and arrays being indexed from 1 which makes converting math equations into code more natural without constantly worrying about off-by-one errors. I wouldn't call multi-dimensional…

e.g. "tensors" are like "vectors" in they transform in a specific way when the coordinate system changes; what felt so magic about vectors as an undergrad was that they embody "the shape of space" and thus simplify calculations. If you didn't have vectors, Maxwell's equations would spill all over the place. Tensors on the other hand are used in places like continuum mechanics and general relativity where something mo…

Sure, but not all arrays are tensors. In continuum mechanics, you often represent tensors as matrices or vectors to exploit symmetry and then it's really confusing to keep calling them tensors because they don't behave like their tensor equivalent.

Re: Learning Fortran (2024)

#52
post #8

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…

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).

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.

Re: Learning Fortran (2024)

#53

Very good choice. Focus on the newest standard.

... if you have access to the Intel compiler tools. gfortran does not support many of the new language features beyond Fortran 2008, even though Fortran 2018 is the defacto "current" standard.

Re: Learning Fortran (2024)

#54
post #8

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…

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.

Re: Learning Fortran (2024)

#55
post #8

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…

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).

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.

Re: Learning Fortran (2024)

#57
post #46

I wonder: is there any reason beyond sheer curiosity* to learn Fortran in 2025? Not being snarky, genuinely curious about what Fortran brings to the table. * Nothing wrong with that as a reason, of course

Yes. Some scientific computing code is still being developed in Fortran eg in HPC. (and has been for decades)

See also OpenMPI FORTRAN support[0].

0 - https://docs.open-mpi.org/en/main/developers/bindings.html#f...

Re: Learning Fortran (2024)

#60
post #46

I wonder: is there any reason beyond sheer curiosity* to learn Fortran in 2025? Not being snarky, genuinely curious about what Fortran brings to the table. * Nothing wrong with that as a reason, of course

Yes; I am seriously thinking of getting the "Modern Fortran Explained" book (https://academic.oup.com/book/56095). Modern Fortran has everything (Procedural, OO, Functional, Multithreading, Parallel etc. features) that all modern languages have. I would say it is no longer "just" for numerical computing. Excellent libraries/ecosystem, a well supported and stable language, fantastic optimization right out of the box etc. makes it a great general purpose language.

Fortran in Modern Scientific Computing: An Unexpected Comeback - https://medium.com/@stack1/fortran-in-modern-scientific-comp...

5 Reasons Why Fortran is Still Used - https://www.matecdev.com/posts/why-fortran-still-used.html

Is Fortran better than Python for teaching the basics of numerical linear algebra? - https://loiseaujc.github.io/posts/blog-title/fortran_vs_pyth...

I take back everything i said about FORTRAN - https://x.com/ThePrimeagen/status/1745542049284423973

Modern Fortran online tutorial - https://wvuhpc.github.io/Modern-Fortran/

Post reply on HN