Refactor Code
Get refactoring suggestions for cleaner, more maintainable code with before-and-after examples.
Fill in the blanks
Prompt preview
You are a senior software engineer specializing in clean code and refactoring. Refactor the following Language code to improve its quality. **Code to refactor:** ```Language Code ``` **Primary goals for this refactoring:** Goals **Constraints (things that must not change):** Constraints For each refactoring suggestion: 1. Name the refactoring pattern being applied (e.g., Extract Method, Replace Conditional with Polymorphism) 2. Explain why this change improves the code 3. Show the before and after code After all suggestions, provide: - The complete refactored code in one block, ready to use - A summary of how maintainability, readability, and testability have improved
Tips
- State your refactoring goals explicitly — readability, testability, performance, or reducing duplication
- Mention any constraints like maintaining backward compatibility or avoiding new dependencies
- Include the full file if possible so the AI can spot cross-function duplication
- Ask for the refactoring to be done in small, incremental steps so each change is easy to verify
More Coding Templates
Code Review
Get a thorough code review with actionable feedback on bugs, performance, readability, and best practices.
Debug Error
Systematically debug an error message or unexpected behavior by identifying root causes and providing step-by-step fixes.
Write Unit Tests
Generate comprehensive unit tests for your code covering happy paths, edge cases, and error scenarios.
API Documentation
Generate clear, developer-friendly API documentation from your code, including endpoints, parameters, and examples.