Ch09 Discussion

Discussion Guide

Warm-up (think–pair–share, 5 min). "You inherit code with six parallel arrays — px, py, pz, vx, vy, vz — indexed in lockstep. Name one bug this invites that a single array of a body type would make impossible." Surfaces the "arrays fall out of step" hazard (Case Study 1, Phase 1).

Main discussion (15–20 min). 1. type vs class. Show the failing type(circle) :: self. Ask why the standard demands class on a passed object even before inheritance exists. Use it to preview Chapter 10 without teaching it. 2. Deep vs shallow copy. Put Example 3 and its pointer-component counterfactual side by side. Have the class predict both outputs, then reason about which default you want for scientific data and why the language made allocatable components deep-copy. Tie to the no-aliasing performance theme. 3. AoS vs SoA. Present the mass-only loop over a million particles. Poll: which layout is faster, and why? Draw the 64-byte cache line over both layouts. Land the point that the derived type did not cause the layout question — it surfaced a choice the parallel arrays had made silently.

Group activity (10 min). In pairs, design a grid_cell type for a finite-volume code: choose its components (center as a nested vec3, volume, temperature, a length-6 flux array), and add a type-bound net_flux(self). One volunteer pair writes their type definition on the board; the class critiques the component choices against the invariant "one control volume and everything true of it." (This is Exercise 9.12.)

Exit ticket. "In one sentence: why does b = a leave a unchanged when a has an allocatable component?" (Checks the §9.4 core; anything naming deep copy / independent storage is a pass.)