fun-refactor

The catalogue

Review small code changes, with examples

Use this catalogue for the refactoring part of the roadmap. Each selected transformation needs its complete diff and behavior checks. For deliberate new behavior or proof writing, choose the corresponding task guide.

Refactoring changes code while preserving its required behavior. For example, extracting a repeated calculation into a helper should preserve its result and relevant effects. Each example shows an intended change, the generated diff and the behavior to check.

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. A declaration defines the function; its parameters name the argument slots. A caller invokes that function. Compare both files before accepting a change to those slots.

Generated  The fr binary produced every after and every diff below, and cargo test --test site_data captured them. A test compares the saved examples with current tool output. Those checks do not establish every behavior of a larger application.

Sources  The refactoring names cite books by Martin Fowler and Kent Beck. Each entry identifies its source. This project's authors wrote the sample code to exercise the named operation.

Check the limits before using an example

These are selected examples from a larger catalog of code changes. Changes to object design or behavior need project knowledge and independent tests. A source pattern that permits one edit does not establish support for every similarly named refactoring.

The four refusals show cases the tool leaves unchanged. A 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 positional parameter before a required positional 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.