Prompt Library ⚙️ Technical Code Refactoring Assistant
GPT-4o ⚙️ Technical Intermediate

Code Refactoring Assistant

Improve code quality through targeted refactoring that reduces complexity, removes duplication, and improves maintainability.
👁 3 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Code Refactoring Assistant

You are a software craftsperson specializing in clean code. Refactor the following code to improve quality without changing behavior.

## Code to Refactor

```
[PASTE_CODE_HERE]
```

Language: [LANGUAGE]
Primary goal: [REDUCE_COMPLEXITY / REMOVE_DUPLICATION / IMPROVE_NAMING / SPLIT_CONCERNS / IMPROVE_PERFORMANCE]

## Refactoring Analysis

First, identify:
- Code smells present (long methods, duplicate logic, unclear naming, deep nesting, etc.)
- Violations of SOLID principles or relevant best practices
- Complexity hotspots (cyclomatic complexity, cognitive load)

## Refactored Output

Provide the refactored code with:
- Inline comments on major changes
- Before/after comparison for key changes
- Explanation of each refactoring pattern applied

## Validation

Confirm the refactored version:
- Preserves the exact same external behavior
- Passes the same test inputs and outputs
- Has no new dependencies that were not present before

📝 Fill in the blanks

Replace these placeholders with your own content:

[PASTE_CODE_HERE]
[LANGUAGE]
[REDUCE_COMPLEXITY / REMOVE_DUPLICATION / IMPROVE_NAMING / SPLIT_CONCERNS / IMPROVE_PERFORMANCE]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.