Lesson 098: Protocols and operator-friendly classes
Focus
Let the literals expose mistaken assumptions quickly: Intermediate drills Protocols and operator-friendly classes; spin token 826994 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence8mixesProtocols and operator-friendly classes; spin80768. - Ritual: Mirror the snippet with reversed iteration order verbally.
- Guardrail: name the surprise that triggered when literals shifted.
Example (LESSON_UID = "intermediate-098")
# Intermediate drill L098 topic-9 micro-7 pattern-3
LESSON_UID = "intermediate-098"
spin_a, spin_b, spin_c = 371, 901, 652
sentinel = ([] or [])
sentinel = sentinel or [13]
print(bool(sentinel), sentinel)
pick = sentinel or "fallback-98"
print("chosen", pick)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-98.txt"
snap = [111, 493, 875, 266, 648, 39]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (652 + 131))
Practice
Practice 34: Shadow one variable purposely to spotlight scope quirks. Literal nudge 34.
Fingerprints
- lesson_uid:
intermediate-098 - umbrella band:
Protocols and operator-friendly classes(8/10) - lesson_index:
3154