Fortran

Guide To Learn

Side-by-side comparison with Python

How does modern Fortran compare to a more recent general-purpose programming language? Python has had the most rapidly growing ecosystem in the past few years for data analysis and light number crunching (http://mng.bz/XP71). It’s used by many Fortran programmers for postprocessing of model output and data analysis. In fact, Python is my second favorite programming language. Because of the application domain overlap between Fortran and Python, it’s useful to summarize key differences between the two, as shown in table 1.1. If you’re a Python programmer, this summary will give you an idea of what you can and can’t do with Fortran.

Table 1.1 Comparison between Fortran and Python (CPython specifically)

LanguageFortranPython
First appeared19571991
Latest releaseFortran 20183.8.5 (2020)
International standardISO/IECNo
Implementation languageC, Fortran, Assembly (compiler-dependent)C
Compiled vs. interpretedCompiledInterpreted
Typing disciplineStatic, strongDynamic, strong
ParallelShared and distributed memoryShared memory only
Multidimensional arraysYes, up to 15 dimensionsThird-party library only (numpy)
Built-in typescharactercomplexintegerlogicalrealboolbytearraybytescomplexdictellipsisfloatfrozensetintlistsetstrtuple
ConstantsYesNo
ClassesYesYes
Generic programmingLimitedYes
Pure functionsYesNo
Higher order functionsLimitedYes
Anonymous functionsNoYes
Interoperability with other languagesC (limited)C
OS interfaceLimitedYes
Exception handlingLimitedYes

From table 1.1, a few key differences between Fortran and Python stand out. First, Fortran is compiled and statically typed, while Python is interpreted and dynamically typed. This makes Fortran more verbose and slower to program but allows the compiler to generate fast binary code. This is a blessing and a curse: Fortran isn’t designed for rapid prototyping, but can produce robust and efficient programs. Second, Fortran is a natively parallel programming language, with syntax that allows you to write parallel code that’s independent of whether it will run on shared or distributed memory computers. In contrast, distributed parallel programming in Python is possible only with external libraries, and is overall more difficult to do. Finally, Fortran is a smaller language that focuses on efficient computation over large multidimensional arrays of a few different numeric data types. On the other side, Python has a much broader arsenal of data structures, algorithms, and general-purpose utilities built in.

In summary, whereas Python is akin to a comprehensive and flexible toolbox, Fortran is like a highly specialized power tool. Fortran thus isn’t well suited for writing device drivers, video games, or web browsers. However, if you need to solve a large numerical problem that can be distributed across multiple computers, Fortran is the ideal language for you.

Side-by-side comparison with Python

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top