Refactoring
When refactoring code:
Before Starting
- Ensure tests exist for code being refactored
- Run tests to establish baseline (must pass)
- If test coverage is low, ADD TESTS FIRST
During Refactoring
- Make ONE type of change at a time
- Keep tests green after EACH change
- Commit frequently with clear messages
Refactoring Types
- Extract: Pull code into new function/class
- Inline: Remove unnecessary indirection
- Rename: Improve naming clarity
- Move: Relocate to better home
- Simplify: Reduce complexity
After Refactoring
- All tests must still pass
- Behavior must be unchanged
- Review diff for unintended changes