Skip to main content

Construction and Semantics Clinic

Complete cluster 6 contracts/ownership before this clinic, and finish it before Module 2. It adds 8–12 focused hours: three lessons and predictions 2–3; representation experiment and change task 3–4; effect tracing and design comparison 2–3; assessment/repair 1–2. Original labs and C01–C10 gates remain. The module is now 88–127 hours; the semester is 473–688. All are unpiloted estimates.

Lesson sequence​

  1. Products, sums and valid states.
  2. Explicit outcomes and observable behavior.
  3. Evaluation order and effects.

Prerequisite repair: if you cannot trace a loop, closure or shared list, return to the module diagnostic and ownership lessons. @dataclass generates routine methods from fields; frozen=True prevents normal field assignment, not arbitrary mutation of contained objects. A tuple is an immutable sequence; use the official documentation linked in the lessons when needed.

Run, change and compare​

Download the experiment. Extract it, enter representation-semantics, and run python3 -B experiment.py. Predict the three-operation example in its README first. Inspect how the independent count oracle compares every intermediate observation and retained state. The 1,280 histories are finite evidence, not a theorem about all programs.

Add requested quantity to Rejected in both representations, update observations and add independently predicted tests. Keep original rejection state unchanged. Explain why this output-contract change affects clients even though inventory arithmetic is unchanged. State why token storage is linear in opening stock while a count stores a single integer (whose bit width grows with its magnitude). No performance superiority is established by the checker.

Implement the callback experiment from Lesson 3. Preserve both output values and call traces; repeat with a callback that raises on its second invocation. Compare a stateful object interface with the pure transition functions: which obligations concern aliasing, which concern case handling, and which remain identical?

Required assessment evidence​

Use the existing 0–3 scale; each item requires at least 2 independently, in addition to C01–C10:

  • DS1 — Model: distinguish products from alternatives and exhibit two invalid combinations in a flag/nullable-field representation. Explain Python's enforcement limits.
  • DS2 — Contract: demonstrate the changed rejection outcome, positive success cases, equality boundary, malformed requests and retained snapshots.
  • DS3 — Semantics: show two transformations with equal-looking expressions but different effect or exception traces; explain the observation boundary.
  • DS4 — Transfer: model Draft/Published documents with explicit data constraints, then add Archived. Identify every affected constructor, operation and client. Defend either a case split or polymorphism for a stated change pattern; neither is universally required.

Retest DS4 with a fresh state after 7–14 days inside the module's existing delayed review session. Replace that session's generic changed-case prompt, not its other competency checks. Keep implementation, traces and reasoning in the existing project packet; no second portfolio.

Calibration and repair​

A strong DS1 answer does not claim a Python union annotation makes invalid construction impossible. DS2 includes taking exactly all remaining stock and rejecting an excessive request without changing it. DS3 includes call count or exception behavior, not only arithmetic output. DS4 distinguishes an archived document from a draft with an empty title and explicitly states allowed transitions. A renamed class diagram without behavior evidence requires repair.

If representations agree but the oracle disagrees, investigate a shared mistaken contract. If only one representation fails, retain its smallest counterexample before repair. This clinic does not replace original ownership, substitution, compatibility or HCI requirements.