GPT-4o
⚙️ Technical
Intermediate
Code Refactoring Guide
Refactor messy or duplicated code into clean, maintainable patterns without breaking functionality.
The Prompt
# Code Refactoring Guide You are a software architect helping someone clean up and restructure existing code. ## The Code - Language and framework: [LANGUAGE/FRAMEWORK — e.g., JavaScript/React, Python, Java] - What this code does: [DESCRIPTION — e.g., fetches user data and renders a dashboard, handles order processing] - Code to refactor: ``` [PASTE YOUR CODE HERE] ``` - What's wrong with it: [PROBLEMS — e.g., too long, lots of copy-pasted logic, hard to test, mixed concerns] - Constraints: [CONSTRAINTS — e.g., can't change the public API, must stay backward compatible, no new dependencies] ## What I Need 1. The refactored code with the same external behavior 2. What patterns or principles I applied (e.g., extract function, single responsibility, DRY) 3. What I changed and why, section by section 4. How to verify the refactor didn't break anything 5. The next refactoring step if I want to go further
📝 Fill in the blanks
Replace these placeholders with your own content:
[LANGUAGE/FRAMEWORK — e.g., JavaScript/React, Python, Java]
[DESCRIPTION — e.g., fetches user data and renders a dashboard, handles order processing]
[PASTE YOUR CODE HERE]
[PROBLEMS — e.g., too long, lots of copy-pasted logic, hard to test, mixed concerns]
[CONSTRAINTS — e.g., can't change the public API, must stay backward compatible, no new dependencies]
How to use this prompt
1
Hit "Run it in your AI"
We open ChatGPT, Claude, Gemini, Perplexity, Grok or Copilot with this prompt in the box, ready for you to press Enter — and copied to your clipboard as a backup. Pick your AI once and we remember it.
2
Replace the placeholders
Swap out anything in [BRACKETS] with your specific details.
3
Send it
This prompt is tuned for GPT-4o, but it works well in any of them. Prefer to do it by hand? Copy to clipboard is always there too.
Get prompts like this every Monday
Free weekly digest — hand-picked prompts, new tools, AI news.