14. Code Review Heuristics
Review for clarity, safety, concurrency correctness, explicit errors, and testability.
Question: What are the key principles you follow when reviewing a teammate's Go code?
Answer: My primary principles are clarity, simplicity, and safety.
Clarity over cleverness: Is the code easy to understand for the next person who reads it?
Small interfaces: Does the code adhere to the interface segregation principle? Components should only depend on the behavior they need.
Explicit error handling: Are all errors checked or explicitly ignored? Does error wrapping add useful context?
Concurrency safety: Is access to shared memory properly synchronized? Are there potential race conditions? Run tests with
-race
.Testability: Is the code structured in a way that makes it easy to unit test? (e.g., dependencies are injected).
API compatibility: Are public contracts stable (wire format/JSON fields)? Avoid breaking changes without versioning.
Performance awareness: Any obvious allocation/time regressions? Consider
b.ReportAllocs()
andpprof
evidence before micro‑optimizing.Security posture: Validate inputs, bound timeouts, handle secrets safely, and avoid leaking PII in logs.
Observability: Emit structured logs with IDs, RED metrics, and trace spans at key boundaries.