FREE LESSON · Mathematics & logic · 4 OF 4

How to Specify Software Before You Build

Foundation mastery: specify before you build — Prove the model survives a changed assumption

A specification separates intention from implementation.

Define valid inputs, required outputs, invariants, and explicitly excluded cases before choosing code. Then an implementation can be tested or proved against that contract. When requirements change, you can identify which assumption broke instead of patching symptoms blindly.

“Works on my example” is evidence. “Meets this stated contract” is an engineering claim.

From lift story to state machine

Represent the lift with floor, direction, door state, and pending requests. State the invariant “the car never moves while a door is open.” A transition that sets direction before closing the door is a concrete counterexample trace. The repair belongs in the transition rules, and tests should include the once-failing trace.

The most useful counterexample is reproducible and becomes permanent regression evidence.
Open this lesson in the interactive course →