It’s got SOLID principles, clean code practices, and .NET tweaks.
# Ultimate Coding Guidelines - SOLID and Clean Code
When generating, reviewing, or modifying code, follow these guidelines combining SOLID principles and clean code practices, with .NET-specific tweaks:
## 1. Single Responsibility Principle (SRP)
- Each class should have one purpose (e.g., separate controllers, services, repositories).
- Keep classes under 150 lines to avoid bloat.
- Separate concerns like logging or validation into dedicated classes.
## 2. Open/Closed Principle (OCP)
- Design classes to be extended without modification.
- Use interfaces and abstract classes for extensibility.
- In .NET, leverage ASP.NET middleware for pipeline extensions.
## 3. Liskov Substitution Principle (LSP)
- Ensure derived classes are fully substitutable for base classes.
- Avoid overriding methods with incompatible behavior.
- In .NET, use generics for type safety.
## 4. Interface Segregation Principle (ISP)
- Create small, client-specific interfaces.
- Avoid forcing classes to implement unused methods.
- In .NET, split `IRepository` into read/write interfaces if needed.
## 5. Dependency Inversion Principle (DIP)
- Depend on abstractions, not concrete classes.
- Use dependency injection (e.g., `Microsoft.Extensions.DependencyInjection` in .NET).
- Avoid direct instantiation with `new` in business logic.
## Clean Code Guidelines
- Use descriptive names for variables, methods, and classes (e.g., avoid `temp`, `x`).
- Keep methods under 20 lines and classes under 150 lines.
- Remove unused variables and imports.
- Use consistent formatting (e.g., prettier for JS/TS, dotnet format for C#).
## Language Support
- Applies to JavaScript, TypeScript, Python, C#, and other OO languages.
- Use ESLint for JS/TS, pylint for Python, Roslyn for C#.
## .NET-Specific Guidelines
- Register services in `Program.cs` for DI.
- Use attributes (e.g., `[Authorize]`) for cross-cutting concerns.
- Follow C# naming conventions (PascalCase for public members).
## Warning Signs
- God classes handling multiple concerns.
- Large controllers or services in .NET.
- Variables named `temp` or `data`.
- Methods with more than 5 parameters.
- Deep inheritance hierarchies or circular dependencies.