Best practices for refactoring with Poolside
- Start with clear objectives: Define specific goals, such as
improve readability,reduce complexityormodernize syntax. Focus on one aspect at a time instead of trying to fix everything simultaneously. - Preserve functionality: Write unit tests before refactoring so that you can verify that the refactored code maintains its original behavior.
- Break down large tasks: For complex refactoring, work in small, incremental steps. Address one method or class at a time.
Simplifying complex methods
Prompt:I have this complex method that's doing too many things. Break it down into smaller, more focused methods.
Converting callbacks to promises
This code is legacy code using callbacks. Modernize it to use async/await
Prompt:
Improving code readability
Prompt:This code works but is hard to read. Make it more expressive and maintainable
Generate design patterns
Prompt:Generate design patterns suggestions could improve this tightly coupled code.
- Tight coupling problem: Direct instantiation of concrete classes
- Need for loose coupling: Dependencies should be injectable
- Maintainability: Code should be easier to test and modify
- Flexibility: Should support different implementations
- Eliminates tight coupling
- Makes unit testing easier (mock dependencies)
- Allows runtime configuration of implementations
- Follows SOLID principles (Open/Closed, Dependency Inversion)