Lesson 055: Classes encapsulating mutable state
Focus
Assume a reviewer executes this verbatim: Intermediate drills Classes encapsulating mutable state; spin token 489720 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence5mixesClasses encapsulating mutable state; spin44624. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: promise one security boundary if this touched user data.
Example (LESSON_UID = "intermediate-055")
# Intermediate drill L055 topic-5 micro-4 pattern-3
LESSON_UID = "intermediate-055"
spin_a, spin_b, spin_c = 683, 49, 191
sentinel = ([] or [])
sentinel = sentinel or [4]
print(bool(sentinel), sentinel)
pick = sentinel or "fallback-55"
print("chosen", pick)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-55.txt"
snap = [68, 759, 459]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (191 + 131))
Practice
Practice 7: Inject a benign off-by-one, observe drift, revert with notes. Literal nudge 7.
Fingerprints
- lesson_uid:
intermediate-055 - umbrella band:
Classes encapsulating mutable state(5/10) - lesson_index:
1757