Read Anthropic’s case study about Graphite Reviewer

Code review comment examples

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite

Code review is a process where developers examine each other’s code changes to find issues, suggest improvements, and maintain code quality over time. This often happens via platforms like GitHub or GitLab, where developers open pull requests and teammates leave inline comments. These code review comments are crucial for guiding code improvements, ensuring architectural consistency, and maintaining a high standard of code readability.

When you open a pull request in GitHub, the platform runs internal checks against your commit diffs (the difference between two sets of files) and attaches code annotations so reviewers can highlight specific lines. Each comment links to a commit hash, so future readers can see exactly which code snippet the comment refers to. When developers incorporate feedback and push new commits, GitHub tracks these changes, updating the conversation thread and allowing reviewers to mark threads as resolved once the recommended improvements are integrated.

In this guide, we’ll break down common examples of code review comments, explain what makes them valuable, and show how to craft more effective messages. We’ll also detail how to implement suggestions right from the terminal using Git commands.

Effective code review comments help build a collective understanding of code quality standards. They reduce frustration that can arise from vague or poorly explained feedback. When comments are specific and grounded in reasons—like highlighting potential bugs, performance issues, or coding style mismatches—they provide actionable steps the author can take to improve. This eventually cultivates a positive development environment where best practices are learned organically, resulting in cleaner code and fewer regressions over time.

When code reviewers find something unclear, they often ask for clarifications. For example:

  • “Could you explain how this calculateTotal() function handles null values?”
  • “This variable name is not very descriptive. Could we rename it to transactionCount?”

Such questions often stem from unfamiliarity with the domain logic or noticing potential ambiguity. This encourages code authors to justify their logic or simplify complex logic, making future maintenance easier.

Sometimes, there’s a more efficient or cleaner way to achieve the same outcome:

  • “Consider using a Map here to eliminate the need for a nested loop.”
  • “This block could be simplified by leveraging the built-in String.format() method.”

Providing alternative approaches teaches developers about new language features, frameworks, or algorithms. This knowledge transfer strengthens the team’s coding proficiency and ensures that code evolves toward simpler, more maintainable solutions.

Early detection of bugs (unexpected behavior caused by incorrect code) is one of the primary goals of code review. Examples include:

  • “This index might go out of range if the list is empty. We should check list.isEmpty() before accessing list.get(0).”
  • “If user is null, calling user.getName() will cause a NullPointerException. Consider adding a null check.”

Comments like these prevent runtime failures and improve code reliability; they also prevent expensive fixes later in the development cycle.

Code style guidelines define how code should look, making it easier to read and maintain. Comments that address style might include:

  • “Please add a space after the comma to match our coding style guidelines.”
  • “This line is too long. Consider breaking it into multiple lines for readability.”

While style-related feedback might seem minor, it makes a huge difference in long-term maintainability. Most codebases have linting tools integrated, so many of these suggestions can be automated.

Positive feedback is also valuable. Highlighting well-structured, well-documented code motivates developers and sets an example:

  • “Nice job refactoring this method. It’s much more readable now.”
  • “Good use of dependency injection here. It really helps isolate components for testing.”

This type of feedback encourages good practices and reinforces the importance of craftmanship in code.

Here are a few examples that combine the above principles:

  • Line 45: Great use of Optional.ofNullable() here. It ensures we handle null values safely.”
  • Line 72: This regex pattern looks correct, but could we add a comment describing what it’s intended to match? That will help future maintainers understand its purpose.”
  • Line 10: Instead of manually iterating over this list and summing values, consider using the stream() API with mapToInt() and sum(). This will simplify the code and might be more performant.”

These comments are specific, actionable, and educational. They highlight the exact location that needs attention and provide a clear improvement path.

When you open a pull request, GitHub uses the Git history to show a diff of changes. Comments attach directly to lines of code via an internal reference to the commit’s hash. As developers push new commits to the branch associated with the pull request, these comments remain anchored. When code changes resolve a particular comment (for example, removing or correcting the problematic line), the reviewer can mark the comment thread as “Resolved”, and GitHub updates the pull request status accordingly.

To address feedback directly, you might do:

Terminal
# Make changes as requested
vim src/MyClass.java
# Stage changes
git add src/MyClass.java
# Commit with a meaningful message
git commit -m "Refactor MyClass to handle nulls and simplify summation logic"
# Push the changes to your branch
git push origin my-feature-branch

GitHub will automatically update the pull request with these new commits, allowing reviewers to revisit and confirm that the suggested improvements were implemented.

Automated checks run in the background whenever a pull request is opened. For example, Continuous Integration (CI) pipelines help ensure that style, performance, and behavior remain consistent. When a reviewer suggests style improvements, these could often be fixed automatically using linting tools. For instance:

Terminal
# Apply automatic formatting fixes using a tool like Prettier
npx prettier --write src/MyClass.java
# Commit and push changes
git add src/MyClass.java
git commit -m "Run Prettier formatting on MyClass"
git push origin my-feature-branch

Over time, automated checks and formatting tools reduce the number of style-related review comments. Developers can then focus on more in-depth logic and architecture discussions during the review.

When leaving comments, remember that there’s a person behind the code. Constructive, empathetic feedback fosters trust and encourages developers to share their work more openly. This leads to a virtuous cycle: more code reviews, better code quality, and stronger teamwork.

Effective code review comments enhance code quality, ensure maintainability, and foster a learning culture. They are specific, justify their suggestions, and remain respectful. By focusing on clarity and helpfulness, teams can use the code review process not just to catch errors, but to continually raise the bar for the entire codebase.

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