FORTRAN is dead! Long live Fortran.

FORTRAN is considered by many to be a dead language. Who even codes in *that* language anymore?

Surprisingly, many scientists do – for numerically intensive computing, including weather prediction models, climate models, and other fluid dynamic simulations. But why, when we have C and C++? The reality is that there is nothing inherently wrong with using Fortran to write programs in.  It’s a language, and it’s somewhat “older” than other languages, but are we going to be ageist about it? In fact in its 60-odd years Fortran has actually evolved – from an unstructured spaghetti-mess to a structured, well-designed language. See the keyword is – evolved – although C has had minor tweaks, there has been no attempt made to evolve-out its idiosyncrasies (dangling-else anyone?).

Amongst computer scientists Fortran has a reputation for being archaic. Few would code in it anymore, even though as far as languages go, Fortran is a versatile, efficient, modern programming language. Sure Fortran 77 was somewhat tawdry, and the unstructured nature of those Fortrans before F77 – downright nauseating. Some of these features hurt the language by impacting its readability, for instance: common blocks; implicit variables; DO loops with shared CONTINUE statements; GOTOs in place of DO loops; Arithmetic IF statements (effectively a goto statement) and computed GOTOs.

So what makes Fortran special? Largely, its ability to deal with mathematical issues, and its propensity to produce efficient code. Languages such as C require only a basic double-precision math library, whereas Fortran requires single AND double precision math, as well as quad-precision offered by many vendors. The latter is sometimes important to minimize roundoff errors. Fortran deals with arrays effectively, allowing arbitrary indexing, slicing, and whole-array operations. Fortran also has better I/O routines than languages such as C – use of read, write, and format (for formatting I/O), is simpler and yet more powerful than equivalent scanf/printf in C. For example, C requires explicit notification of types of data to be input, Fortran does not require it (but you can provided it). Fortran doesn’t rely on the use of pointers as much as C-family languages do. Although explicit pointers are lacking in earlier versions of Fortran, Fortran 90 does allow them, however they are restricted to point only to variables declared with the “target” attribute (more in an upcoming post).

Fortran is also quite easy to learn. Fortran 77 was easier for non-experts to learn than C, even though it still forced the user to write column-dependent code. This is largely related to the fact that the novice programmer did not have to concern themselves with pointers and memory addresses, something that is broached in C with the first scanf used. Not that it isn’t important to understand the use of memory, but not everyone is concerned with this. C was designed as a systems language, Fortran was not – its main goal was number crunching, and still is.

[1] Wirth, Niklaus, Algorithms + Data Structures = Programs, Prentice-Hall (1976)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s