← the guideThe Compiler Age

§ 02 — Eras · 1957

FORTRAN

the oldest language still in production — built for speed

Left: era context, features, and the 101 hello. Right: 3 core concepts, 4 deeper 201 lessons, the factorial specimen, and where FORTRAN lives today — each column scrolls on its own.

creators
John Backus et al., IBM, 1957
status
alive · dominates HPC and weather/climate modeling

The problem it solves

Programmers cost more than machines. FORTRAN let scientists write mathematics and get machine-speed code back from a compiler.

The problem it carries

Punch-card ceremony: fixed columns, six-character names, and dialects that fragmented for decades afterward.

Key features

the DO loop
Counted iteration as a single statement, which the compiler unrolls into straight-line machine code.
array arithmetic
Whole arrays are operated on at once — A = B + C across thousands of elements in one line.
subprograms and libraries
Functions, subroutines and later libraries with explicit interfaces; the model every language since copied.
an optimizing compiler
The first production optimizer in the field — proof that high-level code could run at hand-written speed.

101 — hello, world

Session one is the smallest program that still counts as speaking FORTRAN: what every tutorial prints first, in the dialect that mattered when the language arrived (1957).

the first program1957
print *, "Hello, world"

101First contact — hello world and 3 ideas that define how FORTRAN reads. 201 — 4 lessons on mechanisms you meet after the factorial specimen: the sharp edges practitioners actually use.

101 — core concepts

3 fragments, each naming a habit of mind in FORTRAN. Read the note, then the code — together they are the 101 in one sitting.

01 — the DO loop

FORTRAN’s original workhorse: iterate I from 1 to N, the compiler turns it into tight machine code.

SUM = 0.0
DO I = 1, N
  SUM = SUM + A(I)
END DO

02 — column-agnostic arrays

Arrays are the native data type — one-indexed by default, contiguous in memory, and blindingly fast.

REAL :: A(10, 10)
A(1, 1) = 3.14
PRINT *, SIZE(A)

03 — functions & subroutines

Subprograms with explicit interfaces — the ancestor of every function signature since.

FUNCTION AVG(X, N) RESULT(R)
  REAL :: X(N), R
  R = SUM(X) / N
END FUNCTION

201 — going deeper

The 201 assumes you have read the 101 and the specimen. Each lesson is one mechanism — what it is for, how it looks in code, and the trap or payoff that makes FORTRAN distinctive at scale.

  1. modules and explicit interfaces
  2. derived types
  3. array sections
  4. performance notes

modules and explicit interfaces

Modern Fortran requires the interface of a procedure to be visible at the call site — a direct descendant of the original insistence on typed, checkable calls.

module Geometry
  implicit none
contains
  function area(r) result(a)
    real :: r, a
    a = 3.14159265 * r ** 2
  end function
end module

derived types

User-defined types bundle related data and can carry procedures — the nearest thing FORTRAN has to objects, and a late addition for compatibility.

type :: Ship
  character(len=20) :: name
  real :: tons
end type Ship

type(Ship) :: s
s%name = "Perch"

array sections

Any part of an array can be addressed as a whole, and assignment operates on all of it at once — vectorization without writing a loop.

a(1:10) = b(1:10) * 2.0        ! whole slices
where (a > 0) a = 1.0/a       ! masked assignment

performance notes

Column-major storage means the first index varies fastest — the opposite of C. Getting the loop order wrong can cost two orders of magnitude.

! slow: j varies fastest
do j = 1, n
  do i = 1, m
    a(i,j) = b(i,j) + c(i,j)
  end do
end do

The specimen — factorial

The DO loop, compiled: FORTRAN’s optimizer proved high-level code could match hand-written assembly — and the punch card’s fixed columns set programming’s ceremony for a decade.

the DO loop1957
      SUM = 0.0
      DO 10 I = 1, N
   10 SUM = SUM + A(I)

Run it today

installbrew install gfortran

rungfortran fact.f -o fact && ./fact

Where it is now

The world’s top supercomputers still rank each other with LINPACK benchmarks written in FORTRAN; every weather forecast you have ever received passed through it.