my-git

Code Review Best Practices

English 中文

The core goal of Code Review is to confirm the intent of changes, behavioral boundaries, risks, and long-term maintenance costs.

A good review finds bugs and helps the team maintain shared engineering judgment.

Review Order

We recommend reviewing in this order:

  1. Is the PR goal clear?
  2. Is the diff scope focused?
  3. Do behavioral changes match expectations?
  4. Are tests and validations reliable?
  5. Are error handling and boundary conditions complete?
  6. Are naming, structure, and style consistent with existing code?
  7. Are security risks and rollback paths clear?

What Reviewers Should Ask

Review Standards

Google’s public Code Review documentation emphasizes that the goal of code review is to ensure the codebase remains healthy and continues to improve over time.

This leads to a practical judgment: if a PR clearly improves the system and introduces no obvious risks, reviewers should lean towards approving it, rather than delaying indefinitely over non-critical details.

Teams can categorize comments into three types:

What Authors Should Do

How to Review AI-Generated Code

Pay special attention to AI-generated code:

For details, see AI-Generated Code Review.

Governance Insights from Large Projects

Kubernetes’ OWNERS model splits reviews into two layers: reviewers and approvers. The former focus on code quality, while the latter focus on overall acceptance criteria, compatibility, and long-term impact.

Enterprise teams can learn from this tiering: general reviewers are responsible for finding specific issues, while code owners or module leads are responsible for final approval.

Templates

See Code Review Checklist.

Extended Reading