Read Anthropic’s case study about Graphite Reviewer

Understanding what makes a good code review

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite

Code reviews act as a quality control mechanism that encourage knowledge sharing among team members and reduce the likelihood of bugs in production. However, not all code reviews are effective. This guide will explore what makes a good code review, how to measure code review effectiveness, and the role of tools like Graphite in enhancing the process.

  1. Clarity and focus

    A good code review should focus on specific aspects of the code, such as functionality, performance, security, and adherence to coding standards. Reviewers should ask clear questions and provide actionable feedback rather than vague comments. For instance, instead of saying, "This function is confusing," a better approach would be, "Consider breaking this function into smaller, more manageable functions for better readability."

  2. Constructive feedback

    Feedback should be constructive and aimed at helping the author improve their code. You should avoid harsh criticism or personal attacks. Try using the "sandwich" method when leaving comments: start with a positive note, discuss the areas for improvement, and end with a positive remark. For example:

    • Positive: "I appreciate how you structured the logic in this function."
    • Constructive: "However, I noticed some redundant code that could be simplified."
    • Positive: "Great job overall; your approach is solid!"
  3. Timeliness

    Code reviews should be timely to make sure that developers receive feedback while the context is still fresh. Slow reviews can lead to wasted effort, frustration, and even delayed deployments. Set expectations for turnaround times; for instance, aim for feedback within 24 hours of a pull request being opened.

  4. Knowledge sharing

    A good code review is an opportunity for team members to learn from each other. Encourage reviewers to explain their reasoning behind suggestions, for example, if a reviewer suggests using a particular library for improved performance, they could explain its benefits and provide a reference to the documentation.

  5. Adherence to coding standards

    Consistency in coding standards helps improve readability and maintainability. Reviewers should ensure that the code adheres to the team's coding guidelines. For example, if your team follows a specific naming convention, the reviewer should point out any deviations.

To determine the effectiveness of your code review process, consider using the following metrics:

  1. Review turnaround time

    Measure the time taken for code reviews from submission to approval. A shorter turnaround time usually indicates a more efficient process. Track this metric using tools like Graphite, which provide insights into review times and help identify bottlenecks.

  2. Review rejection rate

    The rate at which code is rejected during review can be an indicator of the quality of submissions and the review process itself. If the rejection rate is high, it may signal a need for better training or clearer guidelines. For example, if a team has a rejection rate of 30%, this may suggest that developers need more guidance on best practices or that the review process is not adequately addressing common issues.

  3. Bug count post-release

    Tracking the number of bugs reported in code after release can help assess the how effective your code reviews are. A lower bug count suggests that the review process is working well, while a higher count indicates potential issues in the review process.

  4. Code churn

    Code churn measures the amount of code that is rewritten or deleted shortly after it is added. High churn can indicate that reviewers missed issues during the review process. Monitoring this metric helps in understanding code stability and reviewer effectiveness. For example, if a module shows a churn rate of over 20% within a week of review, this could indicate that the initial review did not catch critical flaws.

  5. Team satisfaction

    Gather feedback from team members regarding the review process. Use surveys or informal check-ins to understand their perceptions of the code review. Consider asking questions like:

    • Do you feel you receive actionable feedback?
    • Are reviews conducted in a timely manner?
    • How satisfied are you with the collaboration during reviews?

Graphite enhances the code review process in several key ways, providing tools and features that streamline collaboration, improve feedback quality, and increase overall efficiency. Here’s how Graphite contributes to a better code review experience:

  1. Centralized pull request management

    Graphite offers a dedicated inbox for managing pull requests, which allows team members to easily track which PRs need review. The "Needs Review" section ensures that reviewers can quickly identify outstanding requests and prevents important reviews from being overlooked.

  2. Real-time notifications

    Graphite's integration with Slack makes sure you receive instant notifications about PRs that require your attention. This real-time communication keeps everyone informed and helps reduce delays in the review process.

  3. Intuitive commenting system

    Reviewers can hover over line numbers to leave comments, making it easy to provide specific feedback on individual lines or blocks of code. This direct approach makes sure that comments are clear and contextually relevant.

  4. Flexible comment formatting

    The commenting interface supports markdown formatting, which allows reviewers to create structured and easily readable comments. Reviewers can switch between markdown and preview formats, ensuring their feedback is presented clearly and effectively.

  5. One-off and batched comments

    Graphite allows reviewers to choose between posting individual comments or batching them together. Batched comments remain pending until the final review is submitted, helping reviewers organize their feedback and present it cohesively.

  6. Suggested code edits

    Reviewers can leave direct suggestions for code edits, streamlining the feedback loop. Additionally, Graphite's AI-powered Reviewer can assist by catching bugs before a human reviewer has time to conduct a first review, cutting down review cycles.

  7. Comprehensive final review options

    After commenting, reviewers can easily submit a final review with options to request changes, simply add comments, or approve the PR. This flexibility allows for nuanced feedback and better communication regarding the state of the code.

  8. Performance tracking and metrics

    Graphite enables teams to track key metrics related to the code review process, such as review turnaround times and comment activity. This data helps teams evaluate their review effectiveness and identify areas for improvement.

A good code review is characterized by clarity, constructive feedback, timeliness, knowledge sharing, and adherence to coding standards. With a focus on these solid code review elements, teams can continuously improve and keep building high-quality code.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

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