General Principles
These principles apply to all code regardless of language or framework.
Clarity Over Cleverness
Write code for the next developer, not the compiler. Prefer readable, obvious solutions over terse clever ones.
Single Responsibility
Every function, class, and module should do one thing well. If you say "and" when describing it — split it.
Fail Fast & Loudly
Validate inputs early. Throw meaningful errors with context. Never silently swallow exceptions.
No Magic Numbers or Strings
DRY – Don't Repeat Yourself
If you write the same logic more than twice, extract it into a shared function or utility.
Comments
- Write self-documenting code as the default
- Add comments to explain WHY, not WHAT
- Document all public APIs and exported functions
- Keep comments up to date — stale comments are worse than none