Skip to content

B side: Organizing a program

A cassette tape with a handwritten label: "B Side. Fortran, the language that speaks maths."

B B side · Fortran · The language that speaks maths

How do you divide a long text into parts with names?

16 Fortran words in this segment
11 Assembly words for the same job

What Fortran says well here

  • Modules, subroutines, functions and INTENT keep large programs clear.
  • The compiler makes sure that each call matches the procedure.
  • Each table that the B side makes gets a wrong twin: the same program with one wrong word or value. The build requires the check to fail on the twin, so the check itself is tested.

What is hard to say

  • You write more words before the first result.

One sentence in Fortran

module physics
implicit none
contains
pure function next_speed(v, a, dt)
real, intent(in) :: v, a, dt
real :: next_speed
next_speed = v + a*dt
end function
end module

It says: A module named physics with one function that calculates the next speed.

The words, by part of speech

Verbs (1) · A statement that does something, for example PRINT, CALL or ALLOCATE.

WordMeaningExample
CALLRun a subroutine.call draw(ship)

Adjectives (5) · An attribute, for example ALLOCATABLE or PARAMETER.

WordMeaningExample
INTENT(IN)This argument comes in, and the procedure must not change it.real, intent(in) :: dt
INTENT(OUT)The procedure gives this argument its value.real, intent(out) :: v2
PUREThis procedure changes nothing outside itself.pure function f(x)
ELEMENTALWrite the procedure for one value. Fortran then applies it to each value of an array.elemental function f(x)
PRIVATE / PUBLICHide a name inside its module, or show it to other code.private :: helper

Grammar marks (2) · Maths signs (+ - * / **), the = sign, and (:) for part of an array.

WordMeaningExample
!Starts a comment. The compiler ignores the rest of the line.! gravity of the Moon
&The statement continues on the next line.x = a + b + &

Note to the translators (8) · A structure word, for example PROGRAM, MODULE or CONTAINS.

WordMeaningExample
PROGRAMThe start of the primary program.program lander
ENDThe end of a program, module, subroutine or function.end program lander
MODULEA named box of related names and procedures.module physics
USEMake the names in a module available here.use physics
CONTAINSThe procedures come after this line.contains
SUBROUTINEA named procedure that does a job.subroutine draw(ship)
FUNCTIONA named procedure that returns one value.function speed(v)
IMPLICIT NONEEvery name must have a declared type. Without it, old Fortran guesses the type from the first letter.implicit none

Watch out: what the review found

These notes come from the review of the AI-written guides. They show traps that are easy to miss.

  • D01-M5 major In practice this is false. GFortran coarrays need OpenCoarrays, built on MPI (a third-party message-passing library). The Intel implementation uses Intel MPI. MPI+OpenMP dominates production HPC (high-performance computing), so coarrays are niche. The plan puts "distributed memory scaling via coarrays" in weeks 9 to 12, and that goal is aspirational.
  • D01-M7 major LFortran was still pre-1.0 (alpha/beta) at the date of the cited sources. The document recommends it to a 90-day learner as equal to Python/Julia interactivity. That overstates its maturity.
  • D15-C4 critical The 5A22 has a hardware multiplier at $4202/$4203 (8 x 8, result at $4216/$4217, 8 cycles) and a divider at $4204 to $4206 (16 / 8, quotient at $4214/$4215). The reviewer fetched the nesdev "Multiplication" page for the multiplier. A binary to decimal conversion is a few hardware divisions, not 320 cycles. The video says only that BCD "makes the math so much easier" [31:44] and that INC and DEC ignore the decimal flag [32:05]. None of the four chart values is in the video or in report 14. The chart is a picture of an invention.