Hacker News new | ask | show | jobs
by mraza007 1880 days ago
Really that’s interesting, just curious fortran over other languages
2 comments

In many numerical math, you do not need fancy data structures. Just loops over huge arrays of floating point numbers, performing a simple operation inside the loop. Said operation may have a small bit of complexity inside, thus it cannot be "vectorized" readily. Implementing this kind of algorithms is either cumbersome or extremely slow in Python, but in Fortran or C it is straightforward and fast.
The intuition is similar to "why C over other languages?": speed. Many programmers treat C as the fastest/lowest-level cross-platform language, but Fortran sometimes has a slight edge (especially with specialised compilers, e.g. I remember Intel's producing very fast binaries).

Although it's general-purpose, Fortran skews heavily towards numerical calculations, which is probably why it's not used much outside science and engineering (e.g. most Web stuff is 'string processing' rather than numerical).

Fortran was used to write highly optimised numerical libraries like BLAS, which are so widely used and performance-critical that it pretty much cemented Fortran's use; although (a) such libraries can be used by other languages, and (b) they've become so optimised over the decades that they're essentially pure machine-code these days ;)

But interfacing with Fortran from other languages is easy (well, barring some compiler assumptions that everyone seems to be making anyway). Why not leverage the general purpose strength of languages like Rust or C++ or Python (or even C), while still retaining access to the vast trove of numerical Fortran libraries?

(Not that I'm judging, people should use whatever language they prefer).

That's what tends to happen, at least in the code I've worked on. C/C++ for the bits that need to "talk" to the OS, python/perl/bash for scripting purposes, and Fortran for the number-crunching core.