Goal
Rescue a small piece of untested, unreadable legacy code without breaking it: build a safety net around the Gilded Rose inventory logic, refactor it into a design that welcomes change, and prove the rescue by shipping the "Conjured items" feature cheaply. This is the whole legacy-code discipline in an afternoon-sized package.
Subject: full brief & instructions
Practices
- Refactoring techniques — small behavior-preserving steps, smells → named refactorings.
- Testing strategies — characterization/golden-master tests, mutation testing as the honesty check.
- Clean code — naming and structure as the target state.
- TDD — the new feature is written test-first on the cleaned design.
- Design patterns — polymorphism/Strategy emerging from a refactoring, not installed up front.
Milestones
- Read, don't touch. Clone the kata in your language of choice; read the
requirements doc and the code. List the smells you see and the trap the goblin sets
(the
Itemclass may not be modified). - Pin the behavior. Write characterization tests: a golden-master run over ~30 simulated days covering every item type and the edges (sell-in at 0, quality at 0 and 50). Check branch coverage — untested branches are refactoring landmines.
- Mechanical cleanup. Under a green bar only: rename, extract function/variable, flatten the nested conditionals. No behavior change, commits every few minutes.
- Structural refactor. Replace the item-type conditional with polymorphism (one
update strategy per item kind), still without touching
Item. - Ship the feature. TDD "Conjured" items on the new structure. Notice what it costs now versus what it would have cost on day one — that difference is the point.
- Audit the net. Mutation-test the suite (PIT/Stryker); every surviving mutant is a hole in the characterization tests. Kill them.
Stretch goals
- Re-run the kata in a second language from the same repo; compare which refactorings the language makes easy or hard.
- Redo milestone 2 with an approval-testing tool (TextTest, Approvals) and compare effort.
- Time-box a from-scratch second attempt and see how differently you sequence the moves.
Related
- Gilded Rose — legacy rescue — subject — the self-contained work statement: rules, examples, constraints, acceptance checks.
- Refactoring techniques,
Clean code,
Design patterns,
Coupling & cohesion — the concept
notes whose
# Practicecites this project. - Testing strategies, TDD — the safety-net disciplines used throughout.
- Birthday Greetings — hexagonal extraction — the same rescue instinct applied at architecture scale.
- Event-sourced bank account — sibling build project, greenfield instead of legacy.