Standard Coding Style
Enforce coding standards and best practices for AI-assisted development.
Quick Reference
Core Principles:
- •TDD - Write tests first, then implementation
- •KISS - Keep it simple
- •DRY - Don't repeat yourself
- •YAGNI - You aren't gonna need it
- •Readability First - Code is read more than written
Code Smells to Avoid:
- •Functions > 50 lines
- •Nesting > 3-4 levels
- •Magic numbers without constants
Workflow
When writing, reviewing, or refactoring code:
1. Before Writing Code
Read the detailed standards:
code
references/coding-standards.md
Key checks:
- •✅ Tests written first (TDD)
- •✅ External dependencies mocked
- •✅ Following existing architecture
- •✅ Clear, descriptive naming
- •✅ Simplest solution chosen
2. During Implementation
Apply principles actively:
- •Extract repeated code → DRY
- •Split long functions (>50 lines) → smaller functions
- •Use early returns → avoid deep nesting
- •Name constants → no magic numbers
- •Question complexity → KISS
3. After Writing Code
Self-review checklist:
- • Tests pass and cover key paths
- • Functions < 50 lines
- • Nesting < 4 levels
- • No magic numbers
- • No repeated logic
- • Clear variable/function names
- • No premature optimization
Common Patterns
✅ Good: Early Returns
go
func ProcessRequest(user *User) error {
if user == nil {
return errors.New("user is nil")
}
if !user.IsAdmin {
return errors.New("not admin")
}
// Process
return nil
}
❌ Bad: Deep Nesting
go
func ProcessRequest(user *User) error {
if user != nil {
if user.IsAdmin {
// Process
return nil
}
}
return errors.New("invalid")
}
✅ Good: Named Constants
go
const MaxRetries = 3
func Retry() {
if count > MaxRetries {
return
}
}
❌ Bad: Magic Numbers
go
func Retry() {
if count > 3 { // What does 3 mean?
return
}
}
Detailed Standards
For complete guidelines including:
- •TDD testing requirements
- •Code quality principles (KISS, DRY, YAGNI, Readability)
- •Code smell detection patterns
- •Language-specific examples
Read: references/coding-standards.md
When in Doubt
- •Simplicity wins - Choose the clearer solution
- •Ask questions - Clarify requirements before coding
- •Refactor fearlessly - Tests give you confidence
- •Review ruthlessly - Question every line's necessity