Giter Site home page Giter Site logo

effective-code-reviews's Introduction

Effective Code Reviews

Code that actually gets reviewed, and feedback that's actually helpful

David M. Lee, II @leedm777 GitHub @leedm777 Twitter [email protected]


Why Code Review?

  • One of the most cost effective ways to find defects[1]
  • Finds non-defect coding issues (maintainability, readability)
  • Promotes current best practices
  • Educational for all involved

[1]: Code Complete, chapter 20


Tools help, but aren't necessary

You can make git format-patch/svn diff + email work


Rules for effective submissions

“Look, that's why there's rules, understand? So that you think before you break 'em.” – Terry Pratchett


Post small reviews

  • Reviewer effectiveness drops off >400 LOC
  • Be respectful of the reviewer's time

defect density vs LOC

Chart from SmartBear


Post even smaller commits

  • Don't lump several different changes into a single commit
    • Put style/formatting changes into a different commit
    • Break up into logical commits (things you fix along the way, vs. the intent of your submission)
  • git rebase and git commit --fixup is your friend

Write good commit messages

Commit history is the guide to why the code is the way it is.

"Debugging is like being the detective in a crime movie where you are also the murderer." - Filipe Fortes


How to Write a Git Commit Message

From Chris Beams:

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

Use the imperative mood in the subject line

  • “spoken or written as if giving a command or instruction”
  • Examples (again, from Chris Beams)
    • Refactor subsystem X for readability
    • Update getting started documentation
    • Remove deprecated methods
    • Release version 1.0.0
  • Should complete the sentence “If applied, this commit will {{subject-line}}.”

Use the body to explain what and why vs. how

  • how is either implicit in your code, or belongs in code comments
  • what and why provide context; gives reasons for the change
    • What did the code do before the change?
    • Include references to relevant issues in issue tracker
      • Tooling can link commits/builds/issues

how is at best useless, or at worst misleading

commit 6ab909cdb8426c3c05c8ee253bd5002a77f3172b (HEAD -> throw-away)
Author: David M. Lee <[email protected]>
Date:   Wed Aug 16 13:44:32 2017 -0500

    Add 7 to x instead of 5

diff --git a/foo.js b/foo.js
index 50be92d2..a4ab74ed 100644
--- a/foo.js
+++ b/foo.js
@@ -1 +1 @@
-x = x + 5;
+x = x + 6;

why is actually helpful

commit 8c5bc990de82b9c5ec910e582643a9cd9c407bbf (HEAD -> throw-away)
Author: David M. Lee <[email protected]>
Date:   Wed Aug 16 13:44:32 2017 -0500

    Increase timeout increment
    
    When we need to bump up our timeouts (sadly in a variable named `x`), we
    weren't increasing it quite enough to account for slowness of WAN traffic.
    
    See XYZ-8373

diff --git a/foo.js b/foo.js
index 50be92d2..a4ab74ed 100644
--- a/foo.js
+++ b/foo.js
@@ -1 +1 @@
-x = x + 5;
+x = x + 6;

Bitbucket/GitHub: Use mentions to get someone's attention

  • Some of us get too many emails to reasonably handle 553 Unread Emails from Stash
  • Mentions help us filter signal from noise Gmail filter

Rules for effective reviewing

“more what you'd call 'guidelines' than actual rules”


Be polite

XKCD#438

"It's easier to be an asshole to words than to people." - Randall Munroe, XKCD #438


Take your time; take frequent breaks

  • Don't spend more than an hour at a time code reviewing
  • Spend the time to properly understand and review the code

fry-break


Don't blindly approve changes

rubber-stamp

  • If you don't want to review, just remove yourself from it
  • If you're not familiar enough to give it a 👍, just leave feedback and leave it unapproved

Use a checklist

  • Are there unit tests?
  • Is the code clear? Maintainable?
  • Does the code acheive the intended purpose?
  • Should docs be updated? (readme, changelog, api docs, ...)

BitBucket: Use tasks to require a follow-up

use-tasks


Rules for effective tooling

tools


Integrate CI tools with code review

  • Humans can focus on just reading the code
    • Let the bots run the tests and linters

ci-integration


Bitbucket: Set minimum criteria for merging

Require approvers, resolved tasks, successful builds

  • Don't overdo it; if it's too much trouble devs will find a way to avoid it

Bitbucket: Set default reviewers for your repos

No one should ever miss a PR.


Questions?

Any questions?


References

effective-code-reviews's People

Contributors

leedm777 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.