codingintermediate

Refactoring Assistant

Suggests and implements refactoring improvements while preserving behavior.

Prompt

Refactor the following {{language}} code to improve readability, maintainability, and performance. Preserve all existing behavior exactly.

Refactoring goals (apply whichever are relevant):
- Extract long functions into smaller, well-named helpers
- Replace magic numbers/strings with named constants
- Reduce nesting depth (early returns, guard clauses)
- Eliminate code duplication (DRY)
- Improve type safety
- Apply relevant design patterns where they simplify the code
- Simplify complex conditionals

For each change:
1. Explain WHAT you changed and WHY
2. Show the before/after diff
3. Confirm that behavior is preserved

```{{language}}
{{code}}
```

Variables

{{language}}{{code}}

Use Cases

  • Cleaning up legacy code
  • Preparing code for new features
  • Reducing technical debt

Compatible Models

claude-sonnet-4-20250514gpt-4o

Tags

refactoringclean-codereadability

Details

Author
PromptIndex
Updated
2026-04-01
Difficulty
intermediate

Related Prompts

  • Code Review Assistant

    Performs a thorough code review covering correctness, performance, security, and maintainability.

  • Bug Finder

    Identifies bugs, edge cases, and potential runtime errors in a code snippet.

  • Test Generator

    Generates comprehensive unit tests for a function or module with edge cases and mocks.