To be used with github copilot create a file as '.github/copilot-instructions.md' & add below
Before making any code modifications/suggestions, if you identify any unresolved queries or logical inconsistencies whether in the overall project design or the specific code change please ask for clarification before proceeding
Follow all below coding principles and guidelines while making any code changes:
- DRY (Don't Repeat Yourself): Eliminate code duplication to enhance maintainability.
- KISS (Keep It Simple, Stupid): Favor simplicity; avoid unnecessary complexity.
- YAGNI (You Aren't Gonna Need It): Implement features only when necessary.
- SOLID Principles:
- Single Responsibility: Each module/class should have one responsibility.
- Open/Closed: Modules should be open for extension but closed for modification.
- Liskov Substitution: Subclasses should be substitutable for their base classes.
- Interface Segregation: Prefer many specific interfaces over a single general-purpose one.
- Dependency Inversion: Depend on abstractions, not concrete implementations.
- Separation of Concerns: Divide code into distinct sections, each addressing a specific concern.
- Avoid Premature Optimization: Optimize only after identifying performance bottlenecks.
- Law of Demeter: A module should only communicate with its immediate collaborators.
- Composition Over Inheritance: Favor composition to achieve flexibility and reusability.
- Encapsulate What Varies: Isolate the parts of the code that are subject to change.
- Program to an Interface: Depend on abstractions rather than concrete implementations.
- Minimize Coupling: Reduce dependencies between modules to enhance modularity.
- Maximize Cohesion: Ensure that elements within a module are closely related in functionality.
- Boy Scout Rule: Leave the code cleaner than you found it.
- Principle of Least Astonishment: Code should behave in a way that least surprises other developers.
- Fail Fast: Design systems to fail immediately upon encountering an error.
To maintain readability and ease of maintenance, follow these size guidelines:
- Optimal: 100-300 lines per file
- Maximum: 500 lines
- Action Required: If a file exceeds 500 lines, consider splitting it into multiple files with focused responsibilities
- Optimal: 50-200 lines per class
- Maximum: 300 lines
- Action Required: If a class exceeds 300 lines, consider:
- Breaking it into smaller classes
- Using composition to distribute functionality
- Creating mixins or utility classes for shared behaviors
- Optimal: 5-15 lines per method/function
- Maximum: 40 lines
- Action Required: If a function exceeds 40 lines, consider:
- Breaking it into smaller functions with clear names
- Extracting repeated patterns into helper functions
- Using higher-order functions for recurring patterns
- Line Length: Maximum 88 characters per line (follows Black formatter convention)
- Nesting: Maximum 3 levels of nesting for control structures
- Parameters: Maximum 5 parameters per function; use dataclasses or dictionaries for more
- Import Statements: Group imports (standard library, third-party, local) and limit to 15 per file
Remember: These are guidelines, not strict rules. Use judgment when exceptional cases arise, but document why you're exceeding the guidelines when necessary.