Read Anthropic’s case study about Graphite Reviewer

What is a peer code review?

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Peer code review is an examination of a developer’s code by one or more colleagues. This assessment aims to catch errors, ensure adherence to coding standards, and discuss potential improvements. The process provides a structured way for developers to critique and learn from each other, enhancing both the product and the skills of individual team members.

The significance of peer code review cannot be overstated. It serves as an essential quality control measure that helps prevent problematic code from reaching production. By catching issues early, teams can avoid costly and time-consuming repairs later. Moreover, it encourages a team-oriented approach to problem-solving and innovation, as different perspectives often lead to more refined solutions.

The peer review process typically involves several steps:

  1. Preparation: The author of the code makes sure that it meets basic standards and is ready for review.
  2. Review: Reviewers examine the code for readability, functionality, and compliance with project standards.
  3. Feedback: Reviewers provide comments and suggestions. This feedback can range from syntax improvements to architectural advice.
  4. Revision: The original developer considers the feedback and makes necessary changes.
  5. Approval: Once the reviewers are satisfied with the revisions, the code can be merged into the project.

Peer code reviews can vary in format and detail depending on the tools used, the team's policies, and the specific goals of the review. Here are a few examples to illustrate what peer code reviews might look like in different scenarios:

Scenario: A developer submits a pull request (PR) with a new feature implementation.

Review steps:

  1. Reviewer checks out the PR: The reviewer checks out the branch, runs the code, and reviews the changes in the GitHub interface.
  2. Commenting on specific lines: The reviewer adds comments directly on lines of code where changes are suggested. For example:
    • "This loop could potentially lead to a race condition. Consider using a mutex here."
    • "Please add error handling for this file I/O operation."
  3. General feedback: Aside from line-specific comments, the reviewer might add general feedback in the PR's conversation section, such as:
    • "Great use of the strategy pattern here. Makes the component much more flexible."

Scenario: A developer submits a PR for a bug fix in a critical system component.

Review Steps:

  1. Using a redefined checklist: The reviewer uses a checklist that includes items like performance, security, and coding standards.
  2. Filling out the checklist:
    • Performance: "Has the change been profiled with large data sets?"
    • Security: "Are all data inputs validated correctly to prevent SQL injection?"
    • Coding Standards: "Does this follow our naming conventions?"
  3. Approval or request changes: Based on the checklist, the reviewer either approves the PR or requests changes, noting any areas where the PR fails to meet the checklist criteria.

Scenario: Developers engage in a real-time review during the development of a new API.

Review steps:

  1. Real-time coding and discussion: Developers share a live coding session, discussing implementations as they write the code.
  2. Instant feedback: Immediate suggestions and corrections are made during the coding session, such as:
    • "Let’s extract this code into a separate method to improve testability."
    • "I think using a map here instead of a for-loop would simplify this function and reduce complexity."

Scenario: A major version release of a software product involves multiple complex features.

Review Steps:

  1. Pre-Meeting Preparation: All participants review the code independently using tools like GitLab or GitHub.
  2. Meeting Discussion: Team members discuss their findings in a formal meeting, focusing on architectural decisions, potential bugs, and scalability concerns.
  3. Documenting Decisions: Action items and key decisions are documented in the project management tool for future reference.

In any of these scenarios, using a tool like Graphite's PR Inbox can help streamline the process:

  • Organize reviews: By organizing PRs into sections like "Needs Review" or "Approved", teams can keep track of what needs attention.
  • Customize views: Teams can customize and share their views to highlight PRs that are urgent, belong to a specific project, or match other custom criteria.
  • Promote collaboration: Sharing customized sections and filters among the team can help ensure everyone focuses on the right tasks at the right time.

By leveraging technology like Graphite's PR Inbox, teams can simplify their peer code review processes, making them more effective and less time-consuming. This leads not only to better software but also to a stronger, more collaborative team dynamic.

Built for the world's fastest engineering teams, now available for everyone