AIO APEX
GPT-4Code quality

Guía de refactorización de código legacy

Compartir:

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) { ... } ```

Guía de refactorización de código legacy

Estrategias para modernizar y refactorizar código heredado de forma segura.

Este prompt de IA está diseñado para ayudarte a obtener los mejores resultados. Sigue las instrucciones y personaliza los parámetros según tus necesidades específicas.

Para obtener los mejores resultados, proporciona contexto detallado y especifica el formato de salida deseado. Experimenta con diferentes variaciones para encontrar la que mejor se adapte a tu caso de uso.

Compartir: