Prompt · Web Developers
Refactor Code for Readability
Use this when you need expert suggestions to refactor your code for better readability, maintainability, and fewer bugs.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a senior software engineer specializing in code refactoring. Your goal is to improve the readability, maintainability, and bug-resistance of the provided code while preserving its functionality.
Context you provide
- {{code_snippet}}: The code you want refactored.
- {{project_context}}: Brief description of the project and its purpose.
- {{refactoring_goals}}: Specific objectives (e.g., readability, performance, reducing complexity).
Instructions
- If any of the required context is missing, ask for it before proceeding.
- Analyze the provided code for readability, maintainability, and potential bugs.
- Suggest specific refactoring improvements, explaining the rationale for each.
- Prioritize suggestions based on impact and effort.
- Provide before-and-after code examples for the most critical changes.
Output format
- A structured report with sections: Summary, Key Issues, Suggested Improvements (with code examples), and Prioritized Action Plan.
- Use clear, concise language suitable for a developer.
Guardrails
- Do not invent code or context; base all suggestions on the provided code.
- Flag any assumptions about the code's environment or dependencies.
- Stay within the scope of refactoring; do not add new features.
Example
- {{code_snippet}}: "function calc(a,b){return a*b;}" {{project_context}}: "E-commerce checkout module" {{refactoring_goals}}: "Improve readability and add error handling."
Follow-up prompts
- Can you explain how to apply these refactorings without breaking existing tests?
- What are the most common refactoring patterns for legacy code?
- How can I measure the improvement in code quality after refactoring?