Fortran—Programming Language Exploration #1

Kevin Moreland
3 min readMar 22, 2021

An overview of one of the earliest and most impactful programming languages

When you think of old programming languages, which first come to mind? Personally, I first think of FORTAN, BASIC, and COBOL. However, much to my surprise, Fortran (previously named FORTRAN), is still in use today and is actively updated (the most recent release was in 2018). In fact, Fortran today is used commonly for efficient computing in science and engineering contexts.

History

Fortran was developed in 1953 by scientists led by John Backus working at IBM. Before its development, programming was done in much lower level machine code. This method of programming would make the development of many large modern software applications nearly impossible. The following video gives a great overview of the history of the language from the creators themselves:

Programming Language Analysis

Fortran is a compiled programming language. This means that a programmer writes human-readable code which is sent to a compiler to turn it into executable machine-readable code. The opposite of this is an interpreted programming language, which is complied as the program runs. Programs written in complied languages tend to run faster.

Types in Fortran are static, meaning that each variable must be declared explicitly with a type. Here is an example of static typing in Fortran where variables height, width, and area are clearly marked as real numbers:

  real :: height
real :: width
real :: area

width = 4
height = 10
area= width*height

The opposite of this is dynamic typing, such as in Python, where variables can be declared without explicit types like this:

  a = 5
b = "hello world"
c = a + b

According to Fortran’s website, “Fortran allows you to write code in a style that best fits your problem: Imperative, procedural, array-oriented, object-oriented, or functional.” Here is a break down of this:

  • Fortran is imperative. An imperative language provides step-by-step instructions and logic for a computer to follow. This contrasts with markup languages like HTML which are declarative since they describe the end goal of a program and not the instructions to create it.
  • Fortran is array-oriented. In Fortran, one can efficiently perform an operation on all the values in a given set. This is very important for making Fortran an ideal language for computations on large data sets for science applications.
  • Fortran can be procedural. This means it can be written as a series of sequential steps using subroutines and functions to hold logic.
  • Fortran can be object-oriented. This was not part of the original language, but as of 2003 objects and polymorphism exist in Fortran.
  • Fortran can be functional. Before object-oriented programs in Fortran were possible, Fortran was a functional programming langauge, and it still can be used as such. In functional programming languages, a developer writes functions that return outputs given only the values of their inputs and nothing else from outside the function. Data is immutable, meaning the values of variables never change, and functions are passed around like variables. For a more in-depth explanation of procedural versus object-oriented versus functional programming, I recommend the tutorial linked here.

Fortran allows for parallel computing, which means programs in Fortran can run on separate processors on a computer to do many computations simultaneously.

“Hello World” Implementation

It’s time to see Fortran in action! To write “hello world,” follow these steps from Fortran’s official tutorial here:

(I’m using Ubuntu on Windows 10)

  • Install the GNU Fortran compiler by running the following in your terminal:
sudo apt install gfortran
  • Create a new file “hello.f90” with the following contents:
program hello
! This is a comment line, it is ignored by the compiler
print *, 'Hello, World!'
end program hello
  • Compile your human-readable program in “hello.f90” into machine-readable code in the file “hello” with the following command in your terminal:
gfortran hello.f90 -o hello
  • Finally, run your program in your terminal with the below command:
./hello

For more information about Fortran and help on getting starting with it, see their website linked here!

Now get out there and spread your Fortran knowledge!

--

--