Guide de refactoring de code legacy
Why this prompt matters
Refactoring without a plan leads to half-finished migrations. Ordering by risk and ensuring each step is deployable reduces the chance of a blocked release.
What we use it for
Code quality
Prompt
Analyze this legacy code and create a refactoring plan. For each refactoring step: 1) What pattern to apply (extract method, introduce parameter object, etc.), 2) The before/after code, 3) How to verify the refactoring didn't break anything, 4) Estimated risk level. Order steps from lowest to highest risk. Ensure each step is independently deployable.
Result
## Refactoring Plan (5 Steps)
### Step 1: Extract Validation Logic (Risk: Low) **Pattern**: Extract Method **Before**: 45-line function with inline validation **After**: `validateOrder()` + `processOrder()` **Verify**: Existing tests should pass unchanged
### Step 2: Replace Magic Numbers (Risk: Low) **Pattern**: Replace Magic Number with Named Constant ```js // Before if (order.total > 10000) { ... } // After const FREE_SHIPPING_THRESHOLD = 10000; if (order.total > FREE_SHIPPING_THRESHOLD) { ... } ```
Guide de refactoring de code legacy
Stratégies pour moderniser et refactorer du code hérité en toute sécurité.
Ce prompt d'IA est conçu pour vous aider à obtenir les meilleurs résultats. Suivez les instructions et personnalisez les paramètres selon vos besoins spécifiques.
Pour obtenir les meilleurs résultats, fournissez un contexte détaillé et spécifiez le format de sortie souhaité. Expérimentez avec différentes variations pour trouver celle qui convient le mieux à votre cas d'utilisation.