logoalt Hacker News

astro1234 • today at 5:48 PM • 3 replies • view on HN

Having written an open source Fortran library (for x ray scattering and absorption in a particular regime so this is fairly “niche” shall we say), genuinely curious: what if any advantages or strengths does Fortran have these days over other language choices? Are there circumstances where it’s arguably the “right” choice?


Replies

hatmatrix • today at 6:59 PM

A lot of the early, absolute advantages of Fortran (numerical precision, non-aliasing) has been adopted by C.

However what still makes it a great choice is that it still a relatively simple language compared to C, and maps mathematical formulas to code very well. Inelegant code will still run reasonably fast (which is not the true with C) - so all of these points make it actually a programming language where the program is being written by domain experts (i.e., scientists) rather than professional programmers or software engineers.

vintagedave • today at 6:48 PM

May I ask: why did you write that library in Fortran? That is, what was your answer to your question at the time you wrote it?

I have heard that Fortran is very very good at optimizing array processing due to lack of aliases. That may be one answer today. There’s also value in continuity: in using a language for your task because it can build on what others have built. That applies to any established language, of course… but I could see it reasonably applied if someone wrote some kind of numerical processing library today. They’d write it in Fortran and call it from Python!

➕ show 1 reply
12_throw_away • today at 10:20 PM

I mean, I think it's best in class in its niche: writing numerical algorithms that compile to highly optimized machine code, while being reasonably readable and intuitive (at least from F90 on). It's arguably still the easiest way to write compute-intensive numerical extensions for python (well, if it's single-threaded, and if numpy can't do it, and if you're not using GPUs ...).