Slide 1

Slide 1 text

Building Communities with Code Review Alex Gaynor

Slide 2

Slide 2 text

About me • Software Engineer at Rackspace • Frequent Python open source contributor • Django, PyPy, OpenStack, CPython, cryptography.io • Director of the Python Software Foundation I have the unique privilege of being here with *2* sponsors. On behalf of the Python Software Foundation I’m thrilled to be able to be here to speak with you. I want to thank all of the organizers, and all of *you*, the attendees, for being a part of building a strong, diverse, and international Python community.

Slide 3

Slide 3 text

What is code review?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

People reading other people’s code Not an architecture review

Slide 6

Slide 6 text

Why code review?

Slide 7

Slide 7 text

Raise the bus factor Force another person to be familiar enough with the code to pass judgement on it. The more people who understand the code, the more people who’ll be able to maintain it in the future.

Slide 8

Slide 8 text

Ensure readability The properties of readable code and writable code are different. Getting someone who has never had to write the code to read the code makes it more likely the next person who has to read it will be able to.

Slide 9

Slide 9 text

Catch bugs “Given enough eyeballs, all bugs are shallow”, “Many hands make light work”. Other people will catch the things you missed.

Slide 10

Slide 10 text

Encourage a healthy engineering culture People need feedback to get better at their jobs. Code review gives you a structure in which to give people feedback. When feedback is irregular, rather than a core part of the job, feedback can be used for criticism, instead of learning and growth. Everything here works on two conditions. People are acting in good faith, people are committed to not being jerks, and people understand that they are reviewing code and not people. This applies to reviewers and reviews. There are a lot of people who believe that code review requires being a jerk. This is wrong, and this is mean, and I’d much prefer this people just walked away.

Slide 11

Slide 11 text

Ground rules for effective code review

Slide 12

Slide 12 text

Don’t make people do a machine’s work People are good at people things, machines are good at machine things. Code review is not running the tests, or checking for style guide violations, or computing test coverage. Get a CI server to do those. Humans will screw it up because it’s busy work, and machines are better at some types of feedback.

Slide 13

Slide 13 text

Everybody gets code reviewed Code review isn’t something senior engineers do to junior engineers. It’s something everybody does. The person on their first day gets to review the first engineer. No one is above review, no change is above review.

Slide 14

Slide 14 text

Do code review before code gets merged Some people do post-commit code review, meaning code gets landed on master and then it gets reviewed. This promotes a feeling of inevitability, where reviewers don’t want to give what’s perceived as “nit picky” comments because the change is landed already.

Slide 15

Slide 15 text

Every change. Every time. No patch is too small or too simple for code review. I have a 100% rate of patches which are “too small for feedback” breaking the build. This also forces you to have a system where code review is easy, and means you never have an argument about what really is “too small”.

Slide 16

Slide 16 text

How to get started

Slide 17

Slide 17 text

Get a tool • Phabricator • Github • Gerrit • Whatever Get yourself a tool that tracks the history of a patch and lets you leave inline comments. It doesn’t matter what, as long as giving feedback and acting on it is easy.

Slide 18

Slide 18 text

How to be a good patch author

Slide 19

Slide 19 text

Describe what the patch does Make it easy for a reviewer to know what a patch is supposed to do. They have to be able to verify the code you wrote does what you meant it to do.

Slide 20

Slide 20 text

Keep it small A study has show that beyond 200-400 lines of diff, the efficacy of code review decreases, so keep your patches small. A long series of small patches is much better than a few giant patches.

Slide 21

Slide 21 text

Code review is collaborative You need to work with your reviewer to get the best patch. If you disagree with some feedback, talk to them.

Slide 22

Slide 22 text

How to be a good reviewer

Slide 23

Slide 23 text

What are you looking for?

Slide 24

Slide 24 text

What are you looking for? • Intent What is the patch supposed to do? Is it really a bug? Do you really want this feature?

Slide 25

Slide 25 text

What are you looking for? • Intent • Design Is the change in the right place? Did they change some CSS when the HTML was wrong? Did they add javascript to patch the CSS?

Slide 26

Slide 26 text

What are you looking for? • Intent • Architecture • Implementation Does the patch do what it says? Does it do it completely? Does it add new bugs? Does it have documentation and tests? This is the bulk of code review.

Slide 27

Slide 27 text

What are you looking for? • Intent • Architecture • Implementation • Grammar This is the small stuff. Does the variable have a good name? Should something be a keyword argument instead of a positional argument?

Slide 28

Slide 28 text

What are you looking for? • Intent • Architecture • Implementation • Grammar You want to work from intent down to grammar, in order. If you start at grammar, giving feedback on variable name, it’s easy to lose sight of what you’re doing and miss the fact that the patch is totally in the wrong place.

Slide 29

Slide 29 text

Types of review elements As you’re reading through the description of the patch, and the patch itself, you should be leaving comments, here are the types of things you want to be putting into your comments.

Slide 30

Slide 30 text

Types of review elements • TODO These are things that MUST be fixed before a patch can be land, such as a bug or a regression. One of my favorite things to ask for is that more comments be added, it’s very common that I’ll say, “The patch looks fine, but can you add a comment explaining why the code looks this way”

Slide 31

Slide 31 text

Types of review elements • TODO • Questions These are points of clarification. For example “Would this be faster if it was rewritten like so?” or “Can we reuse the logic in the standard library for this?”. Nothing necessarily needs to be done here, it’s just a question for follow up.

Slide 32

Slide 32 text

Types of review elements • TODO • Questions • Suggestions for follow ups These are things that the patch author might want to do, but doesn’t have to, and might be done later. For example when adding a new feature you might suggest that a bug be filed to make it be used somewhere else in the code base.

Slide 33

Slide 33 text

Anti-patterns

Slide 34

Slide 34 text

Very manual processes Makes doing code review a pain, 5 minutes of thoughtful work become 20 minutes of fighting with details of the CI system or issue tracker. Makes people less likely to want to do code review, which is terrible for an OSS project.

Slide 35

Slide 35 text

Irregular When code review is irregular, what that really means is “the new people have to deal with code review, but the rest of us don’t”. This separates the core developers from the new contributors, and that’s crummy, for one it makes it hard for core devs to care about the experience of new people, they dont’ have that experience! It’s also a bad social dynamic.

Slide 36

Slide 36 text

Positive patterns

Slide 37

Slide 37 text

Positive patterns • Share early, share often

Slide 38

Slide 38 text

Positive patterns • Share early, share often • Document the steps

Slide 39

Slide 39 text

Positive patterns • Share early, share often • Document the steps • Lend a helping hand

Slide 40

Slide 40 text

Positive patterns • Share early, share often • Document the steps • Lend a helping hand • Checklists e.g. make sure all documentation contains complete examples

Slide 41

Slide 41 text

Positive patterns • Share early, share often • Document the steps • Lend a helping hand • Checklists • Document your process! e.g. make sure all documentation contains complete examples

Slide 42

Slide 42 text

Code review is an important part of engineering culture I said that we could build communities using code review. How is that?

Slide 43

Slide 43 text

(It also makes it easier to ship good code) The first way is that code review helps us write better code. That’s usually why we do it in the first place. Writing better code makes people more interested in working on our projects, makes them want to stay longer, and makes them enjoy themselves even more. People *like* working with good code.

Slide 44

Slide 44 text

Code review helps people get better When people receive code reviews, it’s pretty clear that it can help them learn how to do their job better. Writing code reviews can do the same things, it helps strengthen our ability to look at brand new code, helps us learn to look for bugs more effectively, and helps us develop better design skills. A key part of building a community is helping new people find their way, and code review is an easy way to do it. It’s often much faster to just say “there were a few issues with this patch, I’ve cleaned them up and committed” them, but if you work with the patch author for them to improve, you’re more likely to get someone really interested in staying around. People *want* to be part of a community that wants to help them improve.

Slide 45

Slide 45 text

Code review makes the core-developers less special One problem open source projects often face is that the core developers are “special”, companies also often have this where very senior developers are special. They can commit stuff on their own, they don’t get feedback from other people. This can be very discouraging to new people. Mandatory code review puts everyone on the same playing field.

Slide 46

Slide 46 text

In Review

Slide 47

Slide 47 text

In Review • Code review should be a part of every team’s workflow

Slide 48

Slide 48 text

In Review • Code review should be a part of every team’s workflow • Use tooling to make the job easier

Slide 49

Slide 49 text

In Review • Code review should be a part of every team’s workflow • Use tooling to make the job easier • Use code review to promote collaboration and learning on your team

Slide 50

Slide 50 text

Thanks! Questions? https://alexgaynor.net — [email protected]