Refactors That Return Copies Can Silently Break Callers Who Rely on In-Place Mutation
A developer argues that characterization tests typically check only return values, missing whether a function alters its arguments in place. Replacing an in-place sort with a sorted copy can keep a test suite passing while production callers continue reading stale data. To catch such changes, the author proposes a Python decorator that snapshots arguments before and after each call and logs any differences to a ledger file. The recommended workflow is to identify candidate mutating functions with grep, wrap them, drive them with recorded real payloads, and commit a stable baseline ledger. The article stresses that the ledger must be deterministic across runs, since run-to-run noise would undermine it as a reliable contract check.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in