Refactoring
Purpose
Improve code structure while preserving behavior.
Core Principles
- •Preserve existing behavior & contracts
- •Small, reversible changes
- •Use tests & tooling to validate
Rules
Planning
- •Identify goal: readability, reuse, or performance
- •Don't mix refactors w/ new features
Execution
- •Refactor in small steps w/ checkpoints
- •Run tests after each significant change
- •Keep public APIs stable when possible
Examples
✅ "Extract function, update tests, replace call sites" ❌ "Rewrite entire module w/o tests"
Edge Cases
- •Tests missing: add characterization tests first
- •High-risk areas: coordinate w/ reviewers before large refactors
See COMMON.md.
Refs: Fowler Refactoring, catalog, guru (2026-01-26)