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 for | Where it shows up | Symptom | Repair evidence |
|---|---|---|---|
| Finishing Behavior Preservation Lab with only a final answer | Behavior Preservation Lab | The 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 answer | Small Refactor Moves Workshop | The 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 answer | Conditional and Data Restructuring Clinic | The 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 answer | Code Katas | The 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 tool | Refactoring Is Behavior Preservation | The 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 tool | The Two Hats: Refactor or Feature, Never Both | The 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:
- "We stopped shipping features for two weeks while we refactored the pricing module."
- "My refactor changed observable behavior but I made all the tests pass by updating them."
- "I don't need tests -- my IDE's Rename refactor is automatic."
- "The characterization test is wrong; it encodes the current bug."
- "I introduced a seam by renaming the parameter."
Small Refactor Moves Workshop
Source: practice/02-small-refactor-moves-workshop.md
- "I extracted a function called
helper." - what is wrong? - "I did Extract Function on a 20-line fragment that assigns three different local variables." - what should come first?
- "I renamed a public API method using the IDE refactor." - when is this fine, when not?
- "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
- "I saw one
switch (type)and built a 4-class hierarchy." - "I consolidated three conditions with
||, not realizing two of them had side effects." - "I introduced a parameter object for 3 parameters that came from 3 unrelated call-site variables."
- "I preserved the whole
Userobject into a function in the logging module." - "I added
isNotEligibleForDisability()and then kept the three original guards."
Repair Protocol
For each real mistake:
- Reproduce the failure on the smallest example, trace, proof, query, command, or design sketch.
- Name the hidden assumption.
- Repair the artifact.
- Save evidence that changed: failing then passing test, corrected proof step, revised diagram, safer command, benchmark, or review note.
- Add one retrieval card beginning with Check... before... or Do not use... when....
Mistake Log
| Date | Mistake | Symptom | Root cause | Repair evidence | Retrieval card |
|---|---|---|---|---|---|
| Starter | Pick one radar row above | Explain how it would fail in this module | Name the assumption | Add a counterexample or corrected artifact | Write 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.