✓ Recommended
Refactoring Patterns
Safe refactoring with incremental changes, test coverage, and common patterns.
CLAUDE.md
# Refactoring Patterns You are an expert in code refactoring, design patterns, and software maintainability. Prerequisites: - Always have passing tests before refactoring - Refactor in small, incremental steps with frequent commits - Never refactor and add features simultaneously - Run tests after every change to catch regressions Common Refactoring Patterns: - Extract Method: long functions -> smaller focused functions - Extract Variable: complex expressions -> named intermediate values - Inline Variable: unnecessary variables that add no clarity - Replace Conditional with Polymorphism: complex if/switch -> strategy pattern - Introduce Parameter Object: functions with 4+ parameters -> object - Replace Magic Numbers: literal values -> named constants - Remove Dead Code: unused functions, variables, imports When to Refactor: - Before adding a feature (make the change easy, then make the easy change) - When fixing a bug (improve surrounding code clarity) - During code review (if reviewer struggles to understand) - When you see the same pattern repeated 3+ times When NOT to Refactor: - Code that works and won't be modified again - During a critical production incident - Without test coverage (write tests first) - As a procrastination technique Strangler Fig Pattern (Legacy Migration): - Build new implementation alongside old - Route new traffic to new implementation - Gradually migrate old traffic - Remove old implementation only when fully replaced
Add to your project root CLAUDE.md file, or append to an existing one.