This is Words and Buttons Online — a collection of interactive #tutorials, #demos, and #quizzes about #mathematics, #algorithms and #programming.

Fortran is still a thing

In 2017 NASA announced a code optimization competition only to cancel it shortly after. The rules were simple. There is a Navier-Stokes equations solver used to model aerodynamics, and basically, the one who makes it run the fastest on the Pleiades supercomputer, wins the first prize.

There were a few caveats though. The applicant had to be a US citizen at least 18 years of age, and the code to optimize had to be in Fortran.

Fortran is not the most popular language in the programmer’s community. Many believe that it’s complex and outdated. Programming in Fortran is perceived like riding a horse-driven carriage to work. Fortran? Isn’t it something that Amish do?

Many thought that the competition will never start due to the lack of applicants. And it was indeed cancelled. Although, for the exact opposite reason.

Quoting NASA's Press Release: «The extremely high number of applicants, more than 1,800, coupled with the difficulty in satisfying the extensive vetting requirements to control the public distribution of the software made it unlikely we would achieve the challenge’s original objectives in a timely manner.»

Marco Librero, NASA Ames Research Center [Public domain],
via Wikimedia Commons

Fortran is not, of course, outdated, and it’s not at all complex. In fact, it has grown into these myths exactly because it is that good at what it does. It was designed to make number-crunching easy and efficient. Its users are scientists and engineers; not computer scientists and software engineers, but the real ones. And when engineers have a tool for the problem, they solve the problem with the tool. The problem comes first, not the code.

That’s how the complexity myth has started. Most of the code you see in Fortran is indeed complex. But this is because:

a) the problem behind it is complex;

b) the code was written by domain specialists and not programmers.

Fortran is simple enough for domain specialist to write bad code and achieve good results with it.

And as for the outdatedness, the current Fortran standard is Fortran 2018. Fortran is constantly being modernized one little step after another. The biggest holding factor here is its mission. It must remain simple for real engineers.

However, the modern Fortran already has modules, objects, generics and built-in support for parallel computing. Foot shooting area grows steadily to meet the fiats of the modern world.

It still excels in the good old structured programming. It has features that mainstream C-like languages lack. For instance, it can exit or continue a loop from a nested loop.

rows: do i = 1, 10
  columns: do j = 1, 10
    if (a(i, j) == 0.) exit rows
    ...
  enddo columns
enddo rows
    

If has case statement with ranges.

integer :: temp_c

! Temperature in Celsius!
select case (temp_c)
case (:-1)
  write (*,*) 'Below freezing'
case (0)
  write (*,*) 'Freezing point'
case (1:20)
  write (*,*) 'It is cool'
case (21:33)
  write (*,*) 'It is warm'
case (34:)
 write (*,*) 'This is Texas!'
end select
    

And it can use an array of indexes to access another array.

real, dimension(5) :: a = [ 2, 4, 6, 8, 10 ]
integer, dimension(2) :: i = [ 2, 4 ]

print *, a(i)   ! prints 4. 8.
    

There is a brief introduction into modern Fortran by Lars Koesterke. If you think Fortran hasn’t changed since the 60s, please look through it. You might get surprised.

So Fortran is not complex and it’s not outdated. Now how come it went underground in the modern world?

The answer here is actually the same as for “where do old programmers go?” They mostly stay in business, but according to the Martin’s lawn, as the number of programmers doubles every five years, they get vastly outnumbered by the younger folks. They just dissolve in a mass. But this is endemic for software industry only. Fortran users are mostly real engineers and scientists, and their numbers don’t grow exponentially. There is more or less the same amount of Fortran users, old and young, as it was some 30 or 40 years ago when Fortran was at its peak.

In a way, it has been at its peak all that time. It’s the world around that has gone crazy. Languages come and go, paradigms ripe and rot, the whole software business is a part of fashion industry now. But when you want your plane to fly, you still need to do the maths with your trusty Fortran. That’s the beauty of the things that work — they don’t have to change much.

More on modern Fortran

Resurrecting Fortran

Fortran-lang accepted to Google Summer of Code 2021

Fortran 2018 Standard