coding•6 prompts
Refactoring Prompts
Refactoring improves code without changing behavior. These prompts help you identify and execute refactoring opportunities safely.
1. Identify Refactoring Opportunities
Best: ClaudeAnalyze this code for refactoring opportunities: [paste code]. Identify: code duplication, overly complex functions, poor naming, violations of SOLID principles, and modernization opportunities. Prioritize by impact and risk.
Start with low-risk, high-impact refactors. Build confidence gradually.
2. Extract Function
Best: ClaudeThis function is too long/complex: [paste function]. Identify logical chunks that could be extracted into separate functions. For each extraction, suggest: function name, parameters, return value, and how it simplifies the original.
Functions should do one thing. Extract until each function has a single purpose.
3. Modernize Legacy Code
Best: ClaudeModernize this [old JavaScript/Python 2/etc.] code to current standards: [paste code]. Update syntax, replace deprecated patterns, use modern language features where beneficial, but preserve exact functionality. Show before/after.
Test thoroughly after modernization. Behavior should not change.
4. Reduce Complexity
Best: ClaudeThis code has high cyclomatic complexity: [paste code]. Refactor to reduce nesting and branching. Consider: early returns, guard clauses, lookup tables instead of switches, and polymorphism. Maintain readability.
Flat is better than nested. Early returns reduce cognitive load.
5. Design Pattern Refactor
Best: ClaudeSuggest design pattern improvements for this code: [paste code]. Identify patterns that could help: where to apply Strategy, Factory, Observer, etc. Explain the benefit and show how the refactored code would look.
Patterns are tools, not goals. Only apply them where they simplify.
6. Safe Refactor Steps
Best: ClaudeI want to refactor [describe change]. Current code: [paste]. Create a step-by-step refactoring plan where each step is independently deployable and testable. No step should break the system.
Small, safe steps are better than big-bang refactors. Ship incrementally.
Try These Prompts with Multiple AIs
Get responses from Claude, ChatGPT, Gemini, and more—all at once. Compare which AI handles these prompts best.
Try Council Free