Refactoring Skill
Use this skill strictly for behavior-preserving code improvements. If you need to fix a bug or add functionality, use the bug-fixing or standard coding flow instead.
Core Principles
- •Zero Behavior Change: The code MUST produce the same output for the same input after refactoring.
- •Small, Reversible Steps: Make incremental changes that can be easily reverted if a test fails.
- •Clean Code Focus: Focus on readability, maintainability (DRY, SOLID), and removing technical debt.
Refactoring Process
- •Baseline: Ensure existing tests pass. If no tests exist, write them before refactoring.
- •Identify Smells: Long methods, dead code, logic duplication, or poor naming.
- •Apply Pattern: Use established patterns like "Extract Method", "Rename Variable", or "Simplified Conditionals".
- •Verify: Run tests after every small change to confirm no breakage.
[!TIP] Refactoring is a "clean as you go" process. It should make future changes easier, not change what the code does today.