5 ms·
I had to dig through some fortran code for my thesis and still don't quite undedsta what exactly it is that makes it so appealing or faster than the same progra
by awild 6y ago
I had to dig through some fortran code for my thesis and still don't quite undedsta what exactly it is that makes it so appealing or faster than the same programs written in C/C++. The syntax seemed excruciatingly old and verbose. Is there actually a reason for its dominance except its Og status?
- fizixer 6y agoNothing makes it appealing or faster than C in particular. It's the stubbornness of the old guard of physics professors (and applied math, etc) who contributed to mountains of (now legacy) fortran code in the 60s, 70s, 80s, and who's funerals haven't occurred yet [0]. [0] https://en.wikipedia.org/wiki/Planck%27s_principle https://en.wikipedia.org/wiki/Planck%27s_principle
- etaioinshrdlu 6y agoC was designed for general purpose computing like operating systems, while fortran was specifically for numerical simulations (for science) and not much else. Due to this legacy, Fortran has better support for arrays, and multidimensional arrays. Also, famously, in Fortran, pointers to data passed to functions are assumed to point to non-overlapping data regions, which allows better optimization of code. C doesn't generally assume this. Apart from that, my understanding is that the "Og" status accounts for a lot of the rest. Fortran compilers are very well optimized.
- retrac 6y agoFortran may be awkward and crufty, but it's got decent numerical computation support, great libraries, great compilers, and runs almost everywhere. Things like that seem to matter more than the language structure.
- pjmlp 6y agoLanguage semantics that make it very hard to achieve the same in C, and in C++ require template metaprogramming libraries like Eigen. Plus since Fortran 2003 it has been quite modern, and we are already a couple of ISO revisions after it, namely Fortran 2018. Ah, and it supports modules, generics, array programming, while being type safe by default.
- m_mueller 6y agoIn order of importance: 1) built-in performant multidimensional arrays, incl. array expressions (similar to Matlab). Built-in nature means basically all numerical libraries can easily talk to each other since they all use compatible data structures. 2) Fortran's syntax is performant by default, so scientists don't have to know as much to produce fast code. Best examples are default pass-by-reference and allocatables instead of pointers, which makes them non-aliased. 3) along same lines: intent system C: restrict const * const double x ... Fortran: real(8), intent(in), allocatable, dimension(n,m) :: x, y, z The second code is simply more expressive about what you think about when doing numerical programming.
- awild 6y agoThe fortran syntax is pretty odd but in contrast to c makes it's very clear. Thanks for the explanation!
- TheRealKing 6y agoPerhaps you were working with FORTRAN77 not Fortran >2003. No other language beats Fortran's syntax for numerical computing. Anyone who claims otherwise, does not really know modern Fortran. Basically, anything nice that one may find about Python, MATLAB, or even C++ Eigen library for numerical computing has been inherited from Fortran.