Commenting
Policy: Minimal Comments
Section titled “Policy: Minimal Comments”Code should be self-documenting. Prefer:
- ✅ Well-named functions and variables
- ✅ Clear types
- ✅ Tests documenting behavior
- ❌ Inline comments explaining obvious code
- ❌ TODO comments (use issues)
- ❌ Commented-out code
Why Minimal Comments?
Section titled “Why Minimal Comments?”- Code is the source of truth — comments can become stale
- Well-named functions explain what they do
- Types document parameters and returns
- Tests document expected behavior
- Git history tracks why changes were made
Instead of Comments
Section titled “Instead of Comments”Instead of Comment Blocks → GoDoc
Section titled “Instead of Comment Blocks → GoDoc”// CreateBackup creates a backup of the given stack.// If includeVault is true, vault secrets are included.func (s *Service) CreateBackup( ctx context.Context, stack string, includeVault bool,) (*BackupManifest, error) { ...}Instead of Inline Comments → Better Names
Section titled “Instead of Inline Comments → Better Names”// Bad: comment explains code// ZFS requires unmount before snapshots.unmountDataset(dataset)
// Good: function name is self-explanatorys.unmountForZFSSnapshot(dataset)Instead of TODO → GitLab Issues
Section titled “Instead of TODO → GitLab Issues”Track work in issues, not code.
Instead of Commented Code → Delete It
Section titled “Instead of Commented Code → Delete It”Use git history if you need to recover old code.
Exceptions
Section titled “Exceptions”The only acceptable inline “comments” are:
- Linter directives:
//nolint:errcheck // fire-and-forget logging- Brief explanations of non-obvious behavior:
// SQLite requires this order due to FK constraintsConfigure linters globally in .golangci.yml rather than using per-file directives when possible.
shc@docs:~$