Lesson 092: Protocols and operator-friendly classes
Focus
Compare against yesterday's mental model politely: Intermediate drills Protocols and operator-friendly classes; spin token 780687 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence2mixesProtocols and operator-friendly classes; spin60582. - Ritual: Swap one benign literal twice to see binding effects.
- Guardrail: name the surprise that triggered when literals shifted.
Example (LESSON_UID = "intermediate-092")
# Intermediate drill L092 topic-9 micro-1 pattern-10
LESSON_UID = "intermediate-092"
spin_a, spin_b, spin_c = 677, 72, 928
def gate(v):
if v < spin_a + 1:
return "low", v ** 2
if v > spin_b + 92:
return "high", v // max(1, 1 + 1)
return "mid", v + spin_c
cand = [3, 92, 73]
for candidate in cand:
lbl, val = gate(candidate)
print(candidate, lbl, val)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-92.txt"
snap = [105, 787, 478, 169]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (928 + 131))
Practice
Practice 3: Promote hottest literal into named constant; justify naming aloud. Literal nudge 3.
Fingerprints
- lesson_uid:
intermediate-092 - umbrella band:
Protocols and operator-friendly classes(2/10) - lesson_index:
2920