Legacy الكود Refactoring Guide
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) { ... } ```
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.
This prompt demonstrates a structured approach to code quality, producing consistent, high-quality results that can be iterated upon.