FM8 — Schema/Contract Violation
A statement is a contract between the writer and the evaluator. The writer claims: “this expression will resolve to True or False.” The evaluator trusts that claim. When the claim is wrong, the contract is violated.
Three ways this happens in practice:
1. Type coercion masks non-boolean values.
Python treats many non-boolean values as truthy or falsy. This is convenient and dangerous.
# Apparent statement: "the response has a body"
if response.body:
process(response.body)If response.body is an empty list, this is False —
correct. If response.body is 0, this is False
— possibly incorrect if 0 is a valid body. If
response.body is None, this is False —
correct. The problem: the code does not distinguish between “body is
empty” and “body is absent.” They are different facts. The statement
conflates them.
2. Stale truth values.
# Evaluated once, held forever
cache_is_warm = precheck_cache()
# ... 500 milliseconds of network calls later ...
if cache_is_warm: # was true 500ms ago; may now be false
read_from_cache() # cache could have been evictedThe statement was True when evaluated. The fact changed. The stored truth value did not. This is not a logic error — it is a temporal contract violation. The statement implicitly claims “the cache is warm right now.” Storing the result breaks that claim.
3. Ambiguous natural language statements mapped to code.
“The user is authorized” — authorized to do what? At what privilege level? From which IP range? In which context?
A natural language statement that sounds definite often has hidden parameters. When mapped to a boolean, those parameters become invisible. The code evaluates the statement for one specific interpretation. Callers assume their interpretation. The contract is violated silently.
# Bad: "is_authorized" — authorized for what?
def is_authorized(user: User) -> bool:
return user.role == "admin"
# Better: explicit about what the statement means
def is_authorized_for_deletion(user: User, resource: Resource) -> bool:
return user.role == "admin" and resource.owner_id == user.idThe second version is a statement with explicit parameters. Its contract is clear.