how to successfully grow a code review culture

114
How to successfully grow a code review culture @nnja Nina Zakharenko

Upload: nina-zakharenko

Post on 11-Jan-2017

2.662 views

Category:

Software


0 download

TRANSCRIPT

Page 1: How to successfully grow a code review culture

How to successfully grow a code review culture

@nnja Nina Zakharenko

Page 2: How to successfully grow a code review culture

What will we learn today? - Part 1

Why do we code review? What are the benefits? Our Code Review Process How to Grow a Culture

Page 3: How to successfully grow a code review culture

What will we learn today? - Part 2

How to be a Great Reviewer How to a be a Great Submitter Using Code Review to Build a Stronger Team

Page 4: How to successfully grow a code review culture

Not one size fits all!

team size 2 vs 10

product type agency vs in-house

defect tolerance jet engines vs mobile games

Page 5: How to successfully grow a code review culture

Why Code Review?

?

Page 6: How to successfully grow a code review culture

Code Reviews Can Be Frustrating

Page 7: How to successfully grow a code review culture

Apparent Code Review Frustrations

Adds time demand Adds process Can bring up team tensions “smart” devs think they don’t need it

Page 8: How to successfully grow a code review culture

How do you get people to change the way they work?

Page 9: How to successfully grow a code review culture

Show them the Benefits are Crystal Clear

Page 10: How to successfully grow a code review culture

Find Design Flaws & Bugs

So they can be identified and remedied before the code is complete Case Studies on Review:

⬇ bug rate by 80%

⬆ productivity by 15%

https://blog.codinghorror.com/code-reviews-just-do-it/

Page 11: How to successfully grow a code review culture

The goal is to find bugs before your customers do.

Page 12: How to successfully grow a code review culture

Shared OwnershipWe’re all in this together

👀 results in positive motivation Overall increase in code quality

Page 13: How to successfully grow a code review culture

Shared Knowledge No developer is the only expert Developers gain familiarity with different modules via review Decrease the “Bus Factor”

Page 14: How to successfully grow a code review culture

🚍 Factor? concentrated specialized knowledge will one person sabotage the project if they left?

Page 15: How to successfully grow a code review culture

Leave a Paper Trail Code Reviews add a wealth of knowledge! Why was a particular decision made?

Page 16: How to successfully grow a code review culture

Find Bugs Shared Ownership Shared Knowledge Reduce Bus Factor Leave a Paper Trail

Code Review Benefits?

Page 17: How to successfully grow a code review culture

My current organization has a great review culture.

As a result, I’ve become a better programmer.

Page 18: How to successfully grow a code review culture

What’s Our Process?

Page 19: How to successfully grow a code review culture

Tools We use GitHub enterprise Many other tools exist GitHub added Review tools September 2016!

Page 20: How to successfully grow a code review culture

Formal Reviews

Page 21: How to successfully grow a code review culture

Inline Comments

Page 22: How to successfully grow a code review culture

Blocked Merging

Page 23: How to successfully grow a code review culture

Workflow

make feature branch

do workopen pull request

Page 24: How to successfully grow a code review culture

Workflow

assign reviewer

complete review

merge branch upstream

Page 25: How to successfully grow a code review culture

Feature Branches? Feature branches are merged into a development branch, not master.

We can QA in a staging environment that mimics production When necessary, we can hotfix master

Page 26: How to successfully grow a code review culture

Grow a Culture

Page 27: How to successfully grow a code review culture

It starts with a Commitment

Make a commitment to always Review before Merge Present the Facts Don’t force it New ideas take time to root

Page 28: How to successfully grow a code review culture

Code Reviews need to be Universal

Doesn’t matter how Senior / Junior you are Only Senior Devs reviewing == bottleneck Inequality breeds dissatisfaction Break down old barriers and status quos

Page 29: How to successfully grow a code review culture

Code Review is done by your peers,

not management.

Page 30: How to successfully grow a code review culture

Consistent Code Your code isn’t yours, it belongs to your Company Code should fit your company’s expectations and style, not your own. Reviews should encourage consistency for code longevity

Page 31: How to successfully grow a code review culture

Style Guide Distinguishes personal taste from functionality Should be agreed upon before hand Great codebases are written by a team, but look like they were written by an individual

Page 32: How to successfully grow a code review culture

Consistent Code is Easier to Maintain by a Team

Page 33: How to successfully grow a code review culture

No Blame Culture Failure is inevitable Mistakes become team, not individual responsibility Needs management support

Page 34: How to successfully grow a code review culture

Blameless Post Mortems Meet shortly after Incident Resolved Understand the root cause Document how it was fixed Identify how to prevent it in future

Page 35: How to successfully grow a code review culture

For a blameless culture, don’t point fingers!

Page 36: How to successfully grow a code review culture

When code reviews are part of the culture, people don’t expect their

changes to be reviewed, they want their changes to be reviewed.

https://www.caktusgroup.com/blog/2014/07/28/culture-code-reviews/

Page 37: How to successfully grow a code review culture

Make a Commitment Universal Code Review Performed by Peers Style Guide = Consistency

How to Grow Culture?

Page 38: How to successfully grow a code review culture

Starts with No Blame Culture

How to Grow Culture?

Page 39: How to successfully grow a code review culture

How should we code review?

?

Page 40: How to successfully grow a code review culture

How to be a Great Reviewer

Page 41: How to successfully grow a code review culture

Have EmpathyWhy do you think you’re so hostile in code reviews?

If only I had been more popular in

High School.

Page 42: How to successfully grow a code review culture

Be Objective“this method is missing a docstring”

instead of “you forgot to write a docstring”

Page 43: How to successfully grow a code review culture

Ask Questions Don’t Give Answers

“Would it make more sense if… ?” “Did you think about… ? ”

Page 44: How to successfully grow a code review culture

Offer Suggestions “it might be easier to” “we tend to do it this way”

Page 45: How to successfully grow a code review culture

Avoid these terms Simply Easily Just Obviously Well, actually…

Page 46: How to successfully grow a code review culture

… now, simply

Page 47: How to successfully grow a code review culture

Have Clear Feedback Strongly support your opinions Share How & Why Link to supporting blogs, stackoverflow examples, or documentation.

Page 48: How to successfully grow a code review culture

Not clear feedback

Page 49: How to successfully grow a code review culture

Compliment Good Work & Great Ideas

Page 50: How to successfully grow a code review culture

Don’t be a perfectionist

Page 51: How to successfully grow a code review culture

Don’t be a Perfectionist For big issues, don’t let perfect get in the way of perfectly acceptable. Prioritize what’s important to you. Usually 90% there is good enough.

Page 52: How to successfully grow a code review culture

It’s OK to Nit-Pick Syntax Issues Spelling Errors Poor Variable Names Missing corner-cases

Page 53: How to successfully grow a code review culture

It’s OK to Nit-Pick

Save the nit-picks for last, after any pressing architecture, design, or other large scale issues have been addressed.

Page 54: How to successfully grow a code review culture

Avoid Burn-OutStudies show reviewer should look at 200-400 lines of code at a time for maximum impact

https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/

Page 55: How to successfully grow a code review culture

https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/

Limit Reviews to 200-400 lines between 60 and 90 minutes, then take a break.

Avoid Burn-Out

Page 56: How to successfully grow a code review culture

Do Reviews in 24-48 hours

Page 57: How to successfully grow a code review culture

Define Done Let the submitter know if you approve, or if they need to make changes. Use consistent language

LGTM or Changes Requested Follow up when the submitter says they fixed something

Page 58: How to successfully grow a code review culture

Have Empathy Watch your Language Have Clear Feedback Give Compliments Don’t be a Perfectionist

How to be a Great Reviewer?

Page 59: How to successfully grow a code review culture

Avoid Burn Out Complete in 24-48 hours Define Done

How to be a Great Reviewer?

Page 60: How to successfully grow a code review culture

How to Be a Great Submitter

Page 61: How to successfully grow a code review culture

Submitter Reviewer

Page 62: How to successfully grow a code review culture

Don’t get rubber-stamped.

Page 63: How to successfully grow a code review culture

Don’t be too clever.

Readability Counts!

Page 64: How to successfully grow a code review culture

Good code is like a good joke. It needs no explanation.

Russ Olsen

Page 65: How to successfully grow a code review culture

Stages of Review 0 before submission 1 submitted 2 (optional) work in progress (30-50%) 3 almost done (90-100%) 4 review completed

Page 66: How to successfully grow a code review culture

step 0: before submission

Page 67: How to successfully grow a code review culture

Provide Context (The Why)

Link to the underlying ticket/issue Document why the change was needed For larger PRs, provide a changelog Point out any side-effects

Page 68: How to successfully grow a code review culture

YOU are the Primary Reviewer Review your code with the same level of detail you would give giving reviews. Anticipate problem areas

Page 69: How to successfully grow a code review culture

The Primary Reviewer Make sure your code works, and is thoroughly tested. Don’t rely on others to catch your mistakes.

Page 70: How to successfully grow a code review culture

Before Submitting, Try a CheckList

Page 71: How to successfully grow a code review culture

☑︎ small stuff Did you check for reusable code or utility methods? Did I remove debugger statements? Are there clear commit messages?

Page 72: How to successfully grow a code review culture

☑︎ big stuff Is my code secure? Will it scale? Read the Checklist Manifesto

Page 73: How to successfully grow a code review culture

step 1: submitted

Page 74: How to successfully grow a code review culture

You’re starting a conversation.

Don’t get too attached to your code before the review process Anticipate comments and feedback Acknowledge you will make mistakes

Page 75: How to successfully grow a code review culture

step 2: (optional)

work in progress

Page 76: How to successfully grow a code review culture

Submit Work in Progress PRs

Necessary for bigger features Open them your code is 30-50% done Don’t be afraid of showing incomplete, incremental work This is the right time to get feedback on bigger issues with the code

Page 77: How to successfully grow a code review culture

When Code is Work in Progress

Feedback to expect: Architectural Issues Problems with Overall Design Design Pattern Suggestions

Page 78: How to successfully grow a code review culture

step 3: almost done

Page 79: How to successfully grow a code review culture

When Code is Almost Done

Feedback to expect: Nit Picks Variable Names Documentation & Comments Small Optimizations

Page 80: How to successfully grow a code review culture

One Review per Issue

Solved an unrelated problem? make a new PR with a separate diff If you’re solving multiple problems, break them up into multiple PRs for ease of review. You can branch off your feature branch to keep the diff small

Page 81: How to successfully grow a code review culture

Prevent Reviewer Burnout

Remember, reviews lose value when they’re more than 500 lines of code. Keep reviews small and relevant. If submitting a big review is unavoidable, give the reviewer extra time.

https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/bosu2015useful.pdf

Page 82: How to successfully grow a code review culture

✔ Check Code with Automated Tools

Page 83: How to successfully grow a code review culture

✔ Lintercheck syntax or style guide violations

Page 84: How to successfully grow a code review culture

✔ Tests Write tests! Don’t know code health if tests are failing Tests Identify problems immediately

Page 85: How to successfully grow a code review culture
Page 86: How to successfully grow a code review culture

✔ Continuous Integration

automated build with every push

Page 87: How to successfully grow a code review culture

✔ Coverage% of code execute when running a test suite

Page 88: How to successfully grow a code review culture

✔ Coverage Coverage tools can integrate into GitHub.

coverage.py

coveralls.io

Page 89: How to successfully grow a code review culture

step 4: review complete

Page 90: How to successfully grow a code review culture

Be Responsive Reply to every comment Common Responses:

Resolved Won’t Fix

If you won’t fix, make sure you’ve come to a mutual understanding with the reviewer

Page 91: How to successfully grow a code review culture

If there were comments, let your reviewer know when you’ve pushed changes and

are ready to be re-reviewed.

It’s still a Conversation

Page 92: How to successfully grow a code review culture

Don’t Bike-Shed bikeshed.com back & forth > 3 times? step away from the keyboard. talk instead! record the conversation in the Review

Page 93: How to successfully grow a code review culture

Fight for what you believe, but gracefully accept defeat.

Page 94: How to successfully grow a code review culture

Don’t take it personally.

It’s an opportunity for growth.

Page 95: How to successfully grow a code review culture

Provide the Why Review your own code Expect Conversation Submit in progress work

How to be a Great Submitter?

Page 96: How to successfully grow a code review culture

How to be a Great Submitter?Use automated tools Be Responsive Accept Defeat

Page 97: How to successfully grow a code review culture

Code Reviews

Build A Stronger

Team

Page 98: How to successfully grow a code review culture

Use that as an advantage when someone new joins!

Page 99: How to successfully grow a code review culture

On your first day…

Page 100: How to successfully grow a code review culture

Newbies

Not everyone has experience being reviewed. Remember what it felt like when you introduced the process.

Ease into it!

Page 101: How to successfully grow a code review culture

On-boarding

Start by reading recently completed reviews. The first submitted review is always the hardest First review should be small. Share the style guide

Page 102: How to successfully grow a code review culture

Everyone’s a Reviewer

Junior devs start by doing pair-reviews with a more experienced teammate. Use it as a mentorship opportunity.

“When your team succeeds, you succeed.”

Page 103: How to successfully grow a code review culture

Hiring senior engineers is hard. You can hire junior engineers, and grow

them into functional productive parts of your team.

Sasha Laundy

http://blog.sashalaundy.com/talks/asking-helping/

Page 104: How to successfully grow a code review culture

If you’re not doing code reviews, you’re missing a big

opportunity.

Page 105: How to successfully grow a code review culture

Remember… Allocate the time Develop, don’t force the culture Not one size fits all Or a one stop fix Use in addition to tests, QA, etc for maximum impact

Page 106: How to successfully grow a code review culture

What did we learn?

?

Page 107: How to successfully grow a code review culture

reviews decrease WTFs/mthe only valid measurement

of code quality

Page 108: How to successfully grow a code review culture

less WTFs ➡ happier devs!

Page 109: How to successfully grow a code review culture

bonus reading & resources at the end of the slides bit.ly/reviewcode

Bonus Material!

Page 111: How to successfully grow a code review culture

Resources & Additional ReadingMicrosoft Study on Effective Code Reviewhttps://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/bosu2015useful.pdf

Code Reviews: Just do ithttps://blog.codinghorror.com/code-reviews-just-do-it/

Code Project - Code Review Guidelineshttp://www.codeproject.com/Articles/524235/Codeplusreviewplusguidelines%20and

Great Example Checklisthttp://insights.dice.com/2012/10/31/whats-on-my-code-review-checklist/

Best Practices for Code Reviewhttps://smartbear.com/learn/code-review/best-practices-for-peer-code-review/

Page 112: How to successfully grow a code review culture

Resources & Additional ReadingRebecca's Rules for Constructive Code Reviewhttps://storify.com/ReBeccaOrg/rebecca-s-rules-for-constructive-code-reviews

My Big Fat Scary Pull Request https://medium.com/@jdan/my-big-fat-scary-pull-request-2c8ac394540e#.yhs96vbxu

Hacker School Environment & Social Rules https://www.recurse.com/manual#sec-environment

Page 113: How to successfully grow a code review culture

Example Style GuidesPython https://www.python.org/dev/peps/pep-0008/

Scala https://github.com/paypal/scala-style-guide

Javascript https://github.com/airbnb/javascript

Google has many good, but strict style guideshttps://github.com/google/styleguide

Doesn't matter which one you use. Pick one and stick with it.

Page 114: How to successfully grow a code review culture

Credits

Special thanks to all the people who made and released these awesome resources for free:

Presentation template by SlidesCarnival