Refactoring Template

This template helps you refactor code to improve maintainability, readability, performance, and testability while preserving existing functionality. It provides structured guidance for code improvements and migration strategies.

Sample Prompt

Refactor this React component to improve:
- Maintainability: Extract custom hooks and separate concerns
- Readability: Better naming and documentation
- Performance: Optimize re-renders and memory usage
- Testability: Make components easier to unit test

[PASTE YOUR CODE HERE]

Preserve existing functionality and provide migration notes.

What This Template Covers

  • Code structure improvements - Breaking down large functions and classes
  • Naming conventions - Better variable, function, and class names
  • Performance optimizations - Reducing complexity and improving efficiency
  • Separation of concerns - Extracting reusable components and utilities
  • Error handling - Adding proper validation and error management
  • Documentation - Improving code comments and self-documenting code

Best Practices

  1. Start small - Focus on one area of improvement at a time
  2. Preserve functionality - Ensure existing behavior remains unchanged
  3. Test before and after - Have comprehensive tests before refactoring
  4. Follow SOLID principles - Single responsibility, open/closed, etc.
  5. Improve naming - Use clear, descriptive names for variables and functions
  6. Extract common patterns - Create reusable functions and components
  7. Add documentation - Include comments for complex logic
  8. Consider performance - Optimize bottlenecks and resource usage

When to Use This Template

  • Improving legacy code quality
  • Preparing code for new features
  • Reducing technical debt
  • Optimizing performance bottlenecks
  • Making code more testable
  • Standardizing coding patterns across teams
  • Before major feature additions
  • During code review improvements

The Script

peep refactoring