The catalogue
Fowler and Beck, worked in Python
A refactoring changes the text of a program and leaves what the program does alone. That is the whole definition, and the only thing every entry here has in common. So every entry says, in its own words, what stayed the same.
Browse twenty-four entries. The tool applies each named move with one command: Extract Function, Guard Clauses, Inline Variable, Reorder Parameters. Every entry shows the before, the after, the diff, and the sentences the tool printed about what it had done. Five entries edit nothing: four are refusals, and one finds work without doing it.
Every file Where a move reaches past the file it started in, every file is here, including the ones that did not have to change. Change a signature without its callers and you have a broken program. So the declaration and the calls appear together, in their own tabs, and you can watch the behaviour move from one to the other and stay the same.
Generated The fr binary produced
every after and every diff below, and
cargo test --test site_data captured them. A
hand-typed “after” claims something about the tool instead of demonstrating it,
and it goes stale the first time the tool improves. That test fails when the page
and the tool disagree.
Whose code The names are Fowler's and Beck's, and each entry says which book and which edition. The code is not theirs: somebody wrote every sample here for this page, in Python, to exercise the move the catalogue describes. Their examples are copyrighted, and a translation of one into Python would be a derivative of it. Go and read them: the books hold the judgement, and no tool has any of that.
What is not here
Most of the catalogue. Both books dwell on moves that need to know what a type is: Replace Conditional with Polymorphism, Replace Primitive with Object, Encapsulate Record. This tool resolves names and leaves types alone. It would have to guess, and a refactoring that guesses is a find-and-replace with better manners.
The three entries that decline mark that boundary, and each declines for a
different reason. Fowler's own Guard Clauses example nests
if/else and assigns to a result. Turning the
else into an early return means deciding what the function returns on
the path that used to fall through, a judgement about the code.
delete refuses anything still referenced, so
fr unused's list is worth acting on. A reorder that would put a
defaulted parameter before a required one gets refused because Python will not run
it. The refactoring has to know that rule, since tree-sitter parses the broken
result without complaint.
Two entries cite neither catalogue and say so. Renaming a CSS class across a stylesheet and the markup that names it is a problem the books predate; dropping unused imports is housekeeping nobody wrote a catalogue entry for. Admitting that beats attaching a plausible-looking section number.
The books
- Refactoring: Improving the Design of Existing Code, 2nd ed., Martin Fowler, 2018.
- Refactoring, 1st ed., Martin Fowler with Kent Beck, 1999, and the online catalogue that carries it forward.
- Tidy First?, Kent Beck, 2023. Small, reversible, one at a time.
- Test-Driven Development by Example, Kent Beck, 2002. Where the refactor step comes from.
- Implementation Patterns, Kent Beck, 2007.