Refactor Code
Process
- •Read current implementation
- •Identify improvement area
- •Apply changes incrementally
- •Verify behavior unchanged
Refactoring Types
| Type | Description |
|---|---|
| Extract | Move code to separate function/class |
| Rename | Improve naming clarity |
| Simplify | Reduce complexity |
| Reorganize | Better file structure |
Rules
- •Keep same external behavior
- •One refactor at a time
- •Run tests after each change
- •Update imports if files move
Extract Pattern
typescript
// Before: inline logic
if (a > b && c < d && e === f) { ... }
// After: extracted function
function shouldProcess(a, b, c, d, e, f): boolean {
return a > b && c < d && e === f;
}
Example
Input: "Refactorise le calcul de dégâts" Output: Extract damage calculation to separate function with clear parameters