1/23/2025
Enhance code quality and maintainability by adhering to DRY (Don't Repeat Yourself) and SOLID (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) principles. This guide provides best practices for writing clean, efficient, and scalable code.
# Optimize (DRY, SOLID Principles)
# Optimize Code with DRY and SOLID Principles
## Communication and Problem-Solving
- **Clarify Requirements**: Always ask for clarification if the task is unclear before proceeding with implementation.
- **Contextual Awareness**: Stick to the current architecture choices (e.g., `pyproject.toml`) unless the user suggests a new method or module.
## Code Quality and Best Practices
- **DRY Principle**: Avoid code duplication by abstracting repeated logic into reusable functions or components.
- **SOLID Principles**:
- **Single Responsibility**: Each function or class should have only one reason to change.
- **Open/Closed**: Code should be open for extension but closed for modification.
- **Liskov Substitution**: Subtypes should be substitutable for their base types without altering the correctness of the program.
- **Interface Segregation**: Prefer small, specific interfaces over large, general ones.
- **Dependency Inversion**: Depend on abstractions, not concretions.
## Paradigms and Principles
- **Functional Programming**: Use pure functions and avoid side effects where possible.
- **Object-Oriented Programming**: Encapsulate behavior and data within classes, adhering to SOLID principles.
## Semantic Naming and Abstractions
- **Descriptive Names**: Use meaningful names for variables, functions, and classes to improve readability.
- **Abstraction**: Create abstractions to hide complex logic and expose only necessary details.
## Platform Thinking
- **Consistency**: Ensure that code adheres to the platform's conventions and best practices.
- **Scalability**: Write code that can scale with the application's growth.
## Response Format
- **Code Blocks**: When outputting code blocks, include a `#` or `//` file name comment prior to the block, with a few lines before and after the modification. This helps the user identify where to make changes.
## Handling Uncertainty and Limitations
- **Ask for Clarification**: If uncertain about any part of the task, ask for more information before proceeding.
- **Document Assumptions**: Clearly document any assumptions made during implementation.
By following these guidelines, you can ensure that your code is clean, maintainable, and adheres to industry best practices.