Skip to main content

Module 2: Refactoring Techniques: Mistake Clinic

This clinic turns wrong moves into reusable judgment. Use it after each practice page and again before the quiz or checkpoint.


Module-Specific Mistake Radar

Start with these traps. Replace or extend them with real mistakes from your own work.

Mistake to look forWhere it shows upSymptomRepair evidence
Finishing Behavior Preservation Lab with only a final answerBehavior Preservation LabThe work has no failed case, trace, test, proof gap, or design stress point.Add the smallest broken example and show the repair that changes the result.
Finishing Small Refactor Moves Workshop with only a final answerSmall Refactor Moves WorkshopThe work has no failed case, trace, test, proof gap, or design stress point.Add the smallest broken example and show the repair that changes the result.
Finishing Conditional and Data Restructuring Clinic with only a final answerConditional and Data Restructuring ClinicThe work has no failed case, trace, test, proof gap, or design stress point.Add the smallest broken example and show the repair that changes the result.
Finishing Code Katas with only a final answerCode KatasThe work has no failed case, trace, test, proof gap, or design stress point.Add the smallest broken example and show the repair that changes the result.
Treating Refactoring Is Behavior Preservation as vocabulary instead of a toolRefactoring Is Behavior PreservationThe explanation names the concept but cannot decide between two cases.Write one example, one non-example, and the rule that separates them.
Treating The Two Hats: Refactor or Feature, Never Both as vocabulary instead of a toolThe Two Hats: Refactor or Feature, Never BothThe explanation names the concept but cannot decide between two cases.Write one example, one non-example, and the rule that separates them.

Practice Mistake Checks

Pull any miss from these checks into your mistake log.

Behavior Preservation Lab

Source: practice/01-behavior-preservation-lab.md

For each statement, identify the error:

  1. "We stopped shipping features for two weeks while we refactored the pricing module."
  2. "My refactor changed observable behavior but I made all the tests pass by updating them."
  3. "I don't need tests -- my IDE's Rename refactor is automatic."
  4. "The characterization test is wrong; it encodes the current bug."
  5. "I introduced a seam by renaming the parameter."

Small Refactor Moves Workshop

Source: practice/02-small-refactor-moves-workshop.md

  1. "I extracted a function called helper." - what is wrong?
  2. "I did Extract Function on a 20-line fragment that assigns three different local variables." - what should come first?
  3. "I renamed a public API method using the IDE refactor." - when is this fine, when not?
  4. "I moved the function and deleted the old call site in the same commit." - how could this burn you?

Conditional and Data Restructuring Clinic

Source: practice/03-conditional-and-data-restructuring-clinic.md

  1. "I saw one switch (type) and built a 4-class hierarchy."
  2. "I consolidated three conditions with ||, not realizing two of them had side effects."
  3. "I introduced a parameter object for 3 parameters that came from 3 unrelated call-site variables."
  4. "I preserved the whole User object into a function in the logging module."
  5. "I added isNotEligibleForDisability() and then kept the three original guards."

Repair Protocol

For each real mistake:

  1. Reproduce the failure on the smallest example, trace, proof, query, command, or design sketch.
  2. Name the hidden assumption.
  3. Repair the artifact.
  4. Save evidence that changed: failing then passing test, corrected proof step, revised diagram, safer command, benchmark, or review note.
  5. Add one retrieval card beginning with Check... before... or Do not use... when....

Mistake Log

DateMistakeSymptomRoot causeRepair evidenceRetrieval card
StarterPick one radar row aboveExplain how it would fail in this moduleName the assumptionAdd a counterexample or corrected artifactWrite the card before closing the page

Completion Standard

  • At least five real mistakes are logged.
  • At least two mistakes include a counterexample or failing test.
  • At least one mistake connects to an older semester skill.
  • At least one correction changes code, a proof, a diagram, a command transcript, a query, or a design decision.