< Return to Video

RailsConf 2015 - Implementing a Strong Code-Review Culture

  • Not Synced
    Good afternoon RailsConf.
  • Not Synced
    I hope you're all doing great after lunch.
  • Not Synced
    Thanks so much for coming.
    I've very excited to be here.
  • Not Synced
    My name is Derek Prior.
    I'm a developer with thoughtbot...
  • Not Synced
    ...and I'm here today to talk to you
    about code reviews, doing them well...
  • Not Synced
    ...and what it means for the culture
    of your team when you are in the
  • Not Synced
    type of place that does them well.
  • Not Synced
    So, let's start with a show of hands.
  • Not Synced
    Just so I get an idea where everyone is at.
  • Not Synced
    How many of you are doing code reviews
  • Not Synced
    as a regular part of your day,
    every day already?
  • Not Synced
    Ok. And how many of you really
    enjoy doing them?
  • Not Synced
    Okay, a few less.
  • Not Synced
    And how many of you do them because
    you feel like you have to?
  • Not Synced
    It's about equal. Okay.
  • Not Synced
    All the people who said they really
    do enjoyed them also said
  • Not Synced
    they do them because they have to.
    Okay.
  • Not Synced
    So, why is it that we do reviews in the first place?
  • Not Synced
    This is pretty easy, right?
  • Not Synced
    To catch bugs.
  • Not Synced
    We're going to have somebody look
    at every individual line of code
  • Not Synced
    and we're going to find what's wrong.
  • Not Synced
    Not really.
  • Not Synced
    That's not why it is interesting, right?
    I've been doing code reviews for
  • Not Synced
    over ten years now.
    I used to hate them.
  • Not Synced
    And, they were the worst
    part of my day.
  • Not Synced
    We did it just for compliance
    documentation at one of my former jobs
  • Not Synced
    But now I think that code reviews are
    one of the primary ways
  • Not Synced
    that I get better at my job
    every single day.
  • Not Synced
    So
  • Not Synced
    Yes, we're gonna have fewer bugs
    in code that's been peer reviewed.
  • Not Synced
    than in code that
    has not been peer reviewed.
  • Not Synced
    But studies on this show that
    the level of QA that we get
  • Not Synced
    out of code review, doesn't meet
    the level of expectation that we have
  • Not Synced
    as developers and managers.
  • Not Synced
    So, that is, we think that by doing
    code reviews we're getting this much QA
  • Not Synced
    when in reality we're getting
    somewhere down here.
  • Not Synced
    So, why is that?
  • Not Synced
    Well, the reason is
    when we do code reviews,
  • Not Synced
    we're looking at a slice of a change.
  • Not Synced
    We're looking at the git diff essentially.
  • Not Synced
    And we can catch syntactical issues,
    or problems where you might be
  • Not Synced
    calling a method on nil.
  • Not Synced
    But we can't catch the really
    heinous stuff which happens when
  • Not Synced
    your whole system interacts
    and corrupts your data.
  • Not Synced
    So, code reviews are good for
    some level of bug catching
  • Not Synced
    but it's not the end-all be-all, right?
  • Not Synced
    So, what are they good for?
    I already told you that I think
  • Not Synced
    that code reviews make me better every day,
    and I want you all to feel the same way
  • Not Synced
    Well, in 2013, Microsoft and the
    University of Lugano in Switzerland
  • Not Synced
    came out with this study: "Expectations,
    Outcomes, and Challenges of Modern
  • Not Synced
    Code Review." So, in it, what they did was
    look at various teams across Microsoft
  • Not Synced
    which is a huge organization - they have
    several teams with different
  • Not Synced
    uh, they have Sr. developers,
    Jr. developers, managers, everybody
  • Not Synced
    all working on a different product.
  • Not Synced
    They surveyed all these people to ask them
    "What is it you get out of code review?
  • Not Synced
    "What do you like about it, what do you
    don't like about it?"
  • Not Synced
    When they were done surveying them,
    they watched them do code review
  • Not Synced
    and asked them questions afterwards.
  • Not Synced
    And, finally, they looked at all of the
    feedback that was given.
  • Not Synced
    Every comment that was logged in their
    code review system.
  • Not Synced
    And they manually classified it
  • Not Synced
    They said "This one has to do with a bug
    that they found. This one has to do with
  • Not Synced
    a style comment. This one has to do with
    a possible alternative solution."
  • Not Synced
    So after doing all this work,
    what they found was that people
  • Not Synced
    consistently ranked finding bugs very high
    as a reason for doing code reviews.
  • Not Synced
    But in the end, it was actually a lot less
    about finding bugs than anyone thought.
  • Not Synced
    The chief benefit they saw from code
    review were Knowledge Transfer,
  • Not Synced
    Increased Team Awareness, and
    Finding Alternative Solutions to problems
  • Not Synced
    That sounds a lot more interesting to me
    than hunting through code looking for bugs.
  • Not Synced
    Through this process we can
    improve our team.
  • Not Synced
    One person involved in the study
    said this:
  • Not Synced
    "Code review is the discipline of
    explaining your code to your peers
  • Not Synced
    that drive a higher standard of coding.
  • Not Synced
    I think the process is even more important
    than the result."
  • Not Synced
    I really do like that last part
    even though it's not on the slide, right?
  • Not Synced
    The process is more important
    than the result. And we're gonna talk
  • Not Synced
    about that today. Just by going through
    the process of code review the right way,
  • Not Synced
    we're going to be improving our team.
    Regardless of the actual results
  • Not Synced
    that we're seeing on any individual change.
  • Not Synced
    But I also like the definition here
    "the discipline of explaining your code
  • Not Synced
    to your peers." I tweak
    it just a little bit to say
  • Not Synced
    rather than trying to explain it to them
  • Not Synced
    Code review is one of the few chances we
    get to have a black-and-white conversation
  • Not Synced
    about a particular change. We often talk
    at abstractions
  • Not Synced
    like when we come to conferences
    like this, we talk in large abstractions
  • Not Synced
    about things. And those are really
    comfortable conversations.
  • Not Synced
    In code review, we have to get down
    to the implementation details
  • Not Synced
    and talk about how we're
    going to apply these things.
  • Not Synced
    So, like so much else that we do,
    it's a communication issue.
  • Not Synced
    If we get better improving code reviews,
    then what we're really doing is improving
  • Not Synced
    the technical communication
    on our team
  • Not Synced
    So, the study also found that
    those benefits I cited earlier
  • Not Synced
    were particularly true for teams that
    had a strong code review culture.
  • Not Synced
    So, what does it mean to have a
    strong code review culture?
  • Not Synced
    To me, it means that your entire team
    has to embrace the process.
  • Not Synced
    Everybody has to be involved. It can't be
    something that the senior developers
  • Not Synced
    do for the junior developers.
    It's a discussion.
  • Not Synced
    That's what we're after here.
  • Not Synced
    So, as I mentioned earlier,
    I've been doing code reviews
  • Not Synced
    for over ten years now. But only in the
    last 2-3 have I started to see a real
  • Not Synced
    improvement in what I'm getting out of
    them, and in myself because of them
  • Not Synced
    And so why is that?
  • Not Synced
    I think it's because I'm part of a strong,
    code review culture at thoughtbot.
  • Not Synced
    And, at thoughtbot we often go to clients
    of various sizes to help them with issues
  • Not Synced
    that they're having. And nobody comes to
    us and says, "I really need help improving
  • Not Synced
    the code review in my team."
    That never happens.
  • Not Synced
    But when we get on the ground
    with those teams, we often find
  • Not Synced
    that there isn't a strong
    code review culture.
  • Not Synced
    One of the challenges that we have
    is how do we get people to have
  • Not Synced
    this culture around code reviews.
  • Not Synced
    And there are a lot of little rules that
    we suggest following in our guides.
  • Not Synced
    But if you look at them, you can
    really boil them down
  • Not Synced
    to two key rules of engagement,
    two things that you can do today
  • Not Synced
    to start getting better at code
    reviews with your team.
  • Not Synced
    The first of them is something
    that you can do as an author.
  • Not Synced
    The second is something
    that you can do as a reviewer
  • Not Synced
    when you're providing feedback.
  • Not Synced
    So first, as an author,
    what are we going to do
  • Not Synced
    to make sure that our code reviews
    get off on the right foot?
  • Not Synced
    So, this quote here is from Gary
    Vaynerchuck and he was talking
  • Not Synced
    about social media marketing,
    or something, not interesting.
  • Not Synced
    But, it's also applicable to code reviews.
  • Not Synced
    Believe it or not.
  • Not Synced
    So, in a code review, your content
    is the code, it's the diff
  • Not Synced
    it's what you've changed.
  • Not Synced
    The context is why that's changed.
  • Not Synced
    Your code doesn't exist for its
    own benefit. It solves a problem.
  • Not Synced
    So the context is
    what problem is it solving.
  • Not Synced
    That study I cited earlier found that
    insufficient context is one of the
  • Not Synced
    chief impediments to a quality review.
  • Not Synced
    So, as an author, we need to get, we need
    to know this and get out in front of it.
  • Not Synced
    We're gonna provide excellent context
    around our changes.
  • Not Synced
    So let's have a look
    at a real world example.
  • Not Synced
    This is a commit, or a pull request title,
    that you might see come across your email.
  • Not Synced
    "Use type column first in
    multi-column indexes"
  • Not Synced
    The specifics here aren't
    particularly important
  • Not Synced
    if you don't understand what this means.
  • Not Synced
    The problem here is that
    there is no why.
  • Not Synced
    So, I can look at this change
    and I can say "Well, yeah, this changes
  • Not Synced
    the order of the indexes, or the order
    of columns on multi-column indexes
  • Not Synced
    But I can't tell you if that was the best
    solution to the problem you're solving.
  • Not Synced
    I can't really learn anything from it.
  • Not Synced
    So, this is a loss. It's not interesting
    for me to review, and it's just going to
  • Not Synced
    get a thumbs up and move on.
  • Not Synced
    Actually, what I would do with a change
    like this is comment and say,
  • Not Synced
    "Can you provide some more context here?"
  • Not Synced
    And a lot of times, what we find happens,
    is somebody updates the pull request
  • Not Synced
    or adds a comment that says
    something like this.
  • Not Synced
    Right?
  • Not Synced
    So, okay, so I guess you guys
    think that's not better, which is true.
  • Not Synced
    That's not better.
  • Not Synced
    So, this is probably a link to Github
    or maybe it's a link to Geer or whatever
  • Not Synced
    your issue tracker is, right?
    And a lot of people do this.
  • Not Synced
    They'll provide a short explanation and
    say, "For more details, see this ticket."
  • Not Synced
    But what you're doing there is you're
    making the reviewer hunt for this context.
  • Not Synced
    If they click this issue, are they gonna
    see a good description of what you're doing?
  • Not Synced
    Probably not, right?
  • Not Synced
    They're gonna see a report of a problem,
    maybe some discussion back and forth
  • Not Synced
    about how to solve it, and then maybe
    a link to this pull request or something.
  • Not Synced
    But they've got to go through all this
    and they've got to hunt for that context
  • Not Synced
    and put it together until they are in the
    right frame of mind to review the changes,
  • Not Synced
    to tell you whether or not
    it is the right solution.
  • Not Synced
    So, here's an improvement.
  • Not Synced
    It's not important to read this, again.
  • Not Synced
    So, what we're doing is identifying
    the problem with index ordering.
  • Not Synced
    That's what we do first.
  • Not Synced
    Why is it a problem?
  • Not Synced
    We're gonna back it up with some
    postgres docs, and those link off to more
  • Not Synced
    information if you need it.
    And because this particular change
  • Not Synced
    was a change to Rails, and we need
    to be concerned with multiple adapters,
  • Not Synced
    we're also going to back it up with some
    MySQL documentation.
  • Not Synced
    And finally, we're gonna talk about
    why this is the best solution.
  • Not Synced
    So that's a lot of context.
  • Not Synced
    But it's important to note that now, as
    somebody is coming along to review this,
  • Not Synced
    I know why this change is being made,
    and maybe I'd even learn something about
  • Not Synced
    how multi-column indexes work, by reading
    through some of this documentation.
  • Not Synced
    So there's value for me to review this.
  • Not Synced
    So, as an author, we're going to
    provide sufficient context.
  • Not Synced
    What we're trying to do here, like
  • Not Synced
    You've been working on this change for
    four hours, two days, however long
  • Not Synced
    it took you to fix this, right?
  • Not Synced
    What you need to do is
    bring the reviewer up to speed.
  • Not Synced
    Let them know what you learned
    in this process,
  • Not Synced
    and put them on equal footing with you.
  • Not Synced
    So I challenge you to provide
    two paragraphs of context
  • Not Synced
    with every change you made.
  • Not Synced
    At first it's going to be really painful,
    and there are some changes that it's
  • Not Synced
    torturous to describe in two paragraphs.
  • Not Synced
    And yes, it's going to take you more time.
  • Not Synced
    But how much more time?
  • Not Synced
    I don't know, like, five minutes, maybe?
  • Not Synced
    And it avoids a whole round of,
    that round of questioning I described
  • Not Synced
    before, like "Why are you making this
    change?" So we've headed that off.
  • Not Synced
    And the extra bonus is that all of that
    context we saw earlier
  • Not Synced
    gets to live on in the commit.
  • Not Synced
    We're gonna squash that
    and we're gonna save that.
  • Not Synced
    So rather than that one we saw before
    that had an issue - a link to G or a link
  • Not Synced
    to Github, that's going to go away
    as soon as we stop paying that bill.
  • Not Synced
    But our git history is going to stay with
    us, and we're going to see that there.
  • Not Synced
    Ok, so that's what we can do
    as an author.
  • Not Synced
    What about as a reviewer?
  • Not Synced
    What can we do to
  • Not Synced
    make it so that our
    feedback is well received?
  • Not Synced
    We like to call this
    ask, don't tell.
  • Not Synced
    To start off with, it's
    important to note that
  • Not Synced
    research has shown there's a negativity
    bias in written communication.
  • Not Synced
    That is to say if I have a conversation
    with you face-to-face and I give you
  • Not Synced
    some feedback, or maybe
    even over the phone,
  • Not Synced
    just in a place where you can hear
    the tone of my voice, hear the inflection.
  • Not Synced
    You're gonna perceive that one way.
  • Not Synced
    If I give you that same feedback written,
    like in the form of a pull request review,
  • Not Synced
    it's going to be perceived
    much more negatively
  • Not Synced
    So, it's important that
    we're cognizant of this
  • Not Synced
    negativity bias in our
    written communication.
  • Not Synced
    We have to overcome this if we want
    our feedback to be taken in the right way.
  • Not Synced
    One way to do that
    is to offer compliments.
  • Not Synced
    I would suggest that you do that.
  • Not Synced
    So, if you find something in a
    pull request that is something you learned
  • Not Synced
    or is something that you think
    is done particularly well,
  • Not Synced
    those are great to call out.
  • Not Synced
    It lets everybody know that...
  • Not Synced
    "Yes, you taught me something.
    That's great. Thank you very much."
  • Not Synced
    Rather than just always nitpicking
    at the change.
  • Not Synced
    But, there's gonna come a time when
    you need to provide critical feedback
Title:
RailsConf 2015 - Implementing a Strong Code-Review Culture
Description:

more » « less
Video Language:
English
Duration:
37:49

English subtitles

Incomplete

Revisions