AIO APEX
GPT-4Code quality

Guia de refatoração de código legacy

Compartilhar:

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

Guia de refatoração de código legacy

Estratégias para modernizar e refatorar código legado de forma segura.

Este prompt de IA foi projetado para ajudá-lo a obter os melhores resultados. Siga as instruções e personalize os parâmetros de acordo com suas necessidades específicas.

Para obter os melhores resultados, forneça contexto detalhado e especifique o formato de saída desejado. Experimente diferentes variações para encontrar a que melhor se adapta ao seu caso de uso.

Compartilhar: