Thoughtbot
Thoughtbot

Code Review

Discover the power of Thoughtbot's comprehensive Code Review Guide, specifically designed to optimize the code review process and boost collaboration among developers. This all-inclusive guide provides invaluable insights and best practices for both reviewing code and having your code reviewed, ensuring a seamless and efficient workflow for every team member.

The Code Review Guide by Thoughtbot places a strong emphasis on open communication, asking meaningful questions, and maintaining a positive and respectful attitude throughout the review process. By adhering to these guidelines, developers can effectively discuss trade-offs, reach resolutions promptly, and cultivate a supportive and inclusive environment for all team members.

Regardless of your experience level, Thoughtbot's Code Review Guide is a must-have resource for enhancing your code review skills and improving your team's overall productivity. Don't miss this chance to elevate your coding expertise and contribute to a more collaborative and successful development process.

Code Review

A guide for reviewing code and having your code reviewed. Watch a presentation that covers this material from Derek Prior at RailsConf 2015.

Everyone

  1. Accept that many programming decisions are opinions. Discuss tradeoffs, which you prefer, and reach a resolution quickly.
  2. Ask good questions; don't make demands. ("What do you think about naming this :user_id?")
  3. Good questions avoid judgment and avoid assumptions about the author's perspective.
  4. Ask for clarification. ("I didn't understand. Can you clarify?")
  5. Avoid selective ownership of code. ("mine", "not mine", "yours")
  6. Avoid using terms that could be seen as referring to personal traits. ("dumb", "stupid"). Assume everyone is intelligent and well-meaning.
  7. Be explicit. Remember people don't always understand your intentions online.
  8. Be humble. ("I'm not sure - let's look it up.")
  9. Don't use hyperbole. ("always", "never", "endlessly", "nothing")
  10. Don't use sarcasm.
  11. Keep it real. If emoji, animated gifs, or humor aren't you, don't force them. If they are, use them with aplomb.
  12. Talk synchronously (e.g. chat, screensharing, in person) if there are too many "I didn't understand" or "Alternative solution:" comments. Post a follow-up comment summarizing the discussion.

Having Your Code Reviewed

  1. Be grateful for the reviewer's suggestions. ("Good call. I'll make that change.")
  2. A common axiom is "Don't take it personally. The review is of the code, not you." We used to include this, but now prefer to say what we mean: Be aware of how hard it is to convey emotion online and how easy it is to misinterpret feedback. If a review seems aggressive or angry or otherwise personal, consider if it is intended to be read that way and ask the person for clarification of intent, in person if possible.
  3. Keeping the previous point in mind: assume the best intention from the reviewer's comments.
  4. Explain why the code exists. ("It's like that because of these reasons. Would it be more clear if I rename this class/file/method/variable?")
  5. Extract some changes and refactorings into future tickets/stories.
  6. Link to the code review from the ticket/story.
  7. Push commits based on earlier rounds of feedback as isolated commits to the branch. Do not squash until the branch is ready to merge. Reviewers should be able to read individual updates based on their earlier feedback.
  8. Seek to understand the reviewer's perspective.
  9. Try to respond to every comment.
  10. Wait to merge the branch until continuous integration (TDDium, Travis CI, CircleCI, etc.) tells you the test suite is green in the branch.
  11. Merge once you feel confident in the code and its impact on the project.
  12. Final editorial control rests with the pull request author.

Reviewing Code

Understand why the change is necessary (fixes a bug, improves the user experience, refactors the existing code). Then:

  1. Communicate which ideas you feel strongly about and those you don't.
  2. Identify ways to simplify the code while still solving the problem.
  3. If discussions turn too philosophical or academic, move the discussion offline to a regular Friday afternoon technique discussion. In the meantime, let the author make the final decision on alternative implementations.
  4. Offer alternative implementations, but assume the author already considered them. ("What do you think about using a custom validator here?")
  5. Seek to understand the author's perspective.
  6. Sign off on the pull request with a 👍 or "Ready to merge" comment.
  7. Remember that you are here to provide feedback, not to be a gatekeeper.

Style Comments

Reviewers should comment on missed style guidelines. Example comment:

> Order resourceful routes alphabetically by name.

1

An example response to style comments:

Whoops. Good catch, thanks. Fixed in a4994ec.

1

If you disagree with a guideline, open an issue on the guides repo rather than debating it within the code review. In the meantime, apply the guideline.

Discover the power of Thoughtbot's comprehensive Code Review Guide, specifically designed to optimize the code review process and boost collaboration among developers. This all-inclusive guide provides invaluable insights and best practices for both reviewing code and having your code reviewed, ensuring a seamless and efficient workflow for every team member.

The Code Review Guide by Thoughtbot places a strong emphasis on open communication, asking meaningful questions, and maintaining a positive and respectful attitude throughout the review process. By adhering to these guidelines, developers can effectively discuss trade-offs, reach resolutions promptly, and cultivate a supportive and inclusive environment for all team members.

Regardless of your experience level, Thoughtbot's Code Review Guide is a must-have resource for enhancing your code review skills and improving your team's overall productivity. Don't miss this chance to elevate your coding expertise and contribute to a more collaborative and successful development process.

Related examples in Code Review Guidelines
Slack
Slack
How About Code Reviews?
Yelp
Yelp
Code Review Guidelines