Chapter 18 — Teaching Notes

One-line purpose. Turn "reading old Fortran" (Ch. 17) into "changing it safely" — an ordered eight-step recipe, applied incrementally, proven correct with a regression test — climaxing in a full before/after modernization of the PLATE kernel.

Key ideas to emphasize

  • Modernization is refactoring, not rewriting. The acceptance test is "the numbers did not move." Say it early, repeat it, and make every step answer to it. The motto "never rewrite what you can refactor" is the emotional and professional core of the chapter.
  • The recipe's ORDER is pedagogy, not bureaucracy. implicit none first because it forces understanding; COMMON→modules is the highest-value single move; error handling last because it is easiest once the code is clean. Have students justify the order, not memorize it.
  • Bit-for-bit vs "close enough" is the intellectual heart. The mechanical/structural steps preserve arithmetic ⇒ demand bit-for-bit; a deliberate precision change ⇒ validate to a justified tolerance. The most common student error is treating a legitimate precision improvement as a regression (Ex. 18.13).
  • Compare numbers, never text. The I5-vs-i0 iteration line in the worked PLATE example is the perfect, concrete illustration — same physics, different whitespace. Point at it explicitly.

Misconceptions to preempt

  • "If it's ugly, rewrite it." (No — the validated behavior is the asset; refactor.)
  • "Bit-for-bit is impossible with floating point." (It is exactly achievable when precision, ops, and order are preserved; it's a property of source + compiler + flags.)
  • "A red regression run means I broke it." (Only for arithmetic-preserving steps. For a deliberate numeric change it means "confirm the improvement and re-baseline.")
  • "In-place update is the same as the two-array update." (No — that's Jacobi → Gauss–Seidel, a different algorithm; different iterates and count. Ex. 18.12, Quiz Q20.)
  • "implicit none will just compile." (No — it forces you to declare everything first; that's the point.)

A live demonstration (10 minutes)

Put the legacy RELAX subroutine on screen. Live-modernize just the convergence loop: convert the GOTO 60 loop to do/exit, and — this is the teaching beat — deliberately get the exit condition WRONG by copying the legacy .GT./.AND. continue test into the exit. Compile, run, watch it "converge" in one iteration. Then fix it to the negation (<= .or. >=) and watch 25 iterations return. Students see, in 90 seconds, both why the negation matters and why you need a regression test to catch it.

Class-time budget (~60 min)

  • 10 min: the recipe and its order (§18.1), with the two-column Modern-vs-Legacy device.
  • 10 min: incremental modernization + "never rewrite what you can refactor" (§18.2).
  • 15 min: regression tests & numerical equivalence; bit-for-bit vs tolerance (§18.3).
  • 20 min: the worked PLATE before/after (§18.4) + the live GOTO demo.
  • 5 min: the Project Checkpoint (two steps on the kernel).

Prerequisites to review

Ch. 8 (modules — students must be fluent, since step 3 is the centerpiece), Ch. 17 (the legacy constructs and the PLATE kernel), Ch. 4 (structured control), Ch. 6 (intent, assumed-shape), Ch. 13 (error stop). A 5-minute recap of what a module buys over COMMON pays off all lesson.

Connections

Back: Ch. 17 (reads the kernel), Ch. 8/6/13/4 (the modern replacements). Forward: Ch. 19 (the translation dictionary tabulates every move and finishes the kernel), Ch. 37 (industrial regression testing, pFUnit, CI — this chapter's hand-rolled harness grown up), Part VIII (a clean modular code is the prerequisite to parallelization).