Guidelines for writing readable, maintainable code that other developers (and your future self) can understand.
- ✅
GetActivePizzas()vs ❌GetPizzas2() - ✅
IsValid()vs ❌Check() - ✅
pizzaRepositoryvs ❌repo,r
Rule: A name should reveal intent in a single glance.
- ✅ Functions under 20 lines
- ✅ One responsibility per function
- ❌ 100-line functions doing multiple things
- ✅ Return
Result<T>for domain errors - ✅ Throw exceptions for system failures
- ❌ Silent failures (no error, no result)
- ❌ Returning null without documentation
- ✅ Explain why, not what (code explains what)
- ✅ Keep comments near the code they describe
- ❌ Outdated comments that contradict code
// ✅ GOOD: Explains why
// We use exponential backoff to avoid overwhelming the API
// during thundering herd scenarios
await Task.Delay(exponentialBackoff);
// ❌ BAD: Explains what (code is already clear)
// Increment counter
count++;- ✅ Unit test domain logic
- ✅ Integration test repositories + database
- ✅ Negative paths first (failures before happy path)
- ❌ No tests
- ❌ Tests that don't fail when code breaks
- ✅ Simple if/else chain vs. complex nested logic
- ✅ One reason to change per class (SRP)
- ❌ Over-engineering for hypothetical future features
- ✅ Extract common logic to functions/classes
- ✅ Reuse validation rules
- ❌ Copy-paste code across files
- ✅ Auto-formatter (Prettier, Roslyn, Black, gofmt)
- ✅ Consistent indentation, spacing, line length
- ❌ Mixed styles (2 spaces, then 4 spaces)
- C#: https://github.com/entelect-incubator/Design-Patterns/tree/main/Clean-Code/csharp
- Java: https://github.com/entelect-incubator/Design-Patterns/tree/main/Clean-Code/java
- Python: https://github.com/entelect-incubator/Design-Patterns/tree/main/Clean-Code/python
- TypeScript: https://github.com/entelect-incubator/Design-Patterns/tree/main/Clean-Code/typescript
Every phase enforces:
- Naming: Variables, functions, classes reveal intent
- Length: Functions < 20 lines, classes < 200 lines
- Testing: Negative paths covered, no untested code
- Comments: Only where intent is unclear
- Formatting: Linter and formatter run without warnings
- DRY: No duplicate logic
- SOLID: Classes have single responsibility
| Language | Formatter | Linter | Type Checker |
|---|---|---|---|
| C# | dotnet format | StyleCop | Built-in |
| Java | Google Java Format | Checkstyle | Built-in |
| Python | Black | Pylint/Flake8 | mypy |
| TypeScript | Prettier | ESLint | TypeScript compiler |