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.

  1. Clarity over cleverness: Is the code easy to understand for the next person who reads it?

  2. Small interfaces: Does the code adhere to the interface segregation principle? Components should only depend on the behavior they need.

  3. Explicit error handling: Are all errors checked or explicitly ignored? Does error wrapping add useful context?

  4. Concurrency safety: Is access to shared memory properly synchronized? Are there potential race conditions? Run tests with -race.

  5. Testability: Is the code structured in a way that makes it easy to unit test? (e.g., dependencies are injected).

  6. API compatibility: Are public contracts stable (wire format/JSON fields)? Avoid breaking changes without versioning.

  7. Performance awareness: Any obvious allocation/time regressions? Consider b.ReportAllocs() and pprof evidence before micro‑optimizing.

  8. Security posture: Validate inputs, bound timeouts, handle secrets safely, and avoid leaking PII in logs.

  9. Observability: Emit structured logs with IDs, RED metrics, and trace spans at key boundaries.