Code Refactoring Guide
Get a step-by-step refactoring plan for messy code
codingrefactoringclean-codepatterns
Prompt Template
Refactor this {language} code to improve {goal}:
```{language}
{code}
```
Provide:
1. Analysis of current issues
2. Refactoring strategy (approach and order)
3. Step-by-step changes with before/after
4. Explanation of design patterns applied
5. Final refactored version
6. Tests to verify behavior is preservedVariables
{language}Example: TypeScript
{goal}Example: readability and maintainability
{code}Example: // messy 200-line function...
Example Output
## Analysis 1. **God function**: Single function handling validation, processing, and formatting 2. **Repeated logic**: Similar null checks appear 4 times...
Tips
- Explain what the code does (not just the code)
- Mention if there are tests you need to keep passing