run Ministry of Velocity, a consulting company here in San Francisco. ! We help companies like yours get better at refactoring and object oriented design in Javascript, Go and Ruby. ! We also help teams get better at interviewing, communicating and code review.
code review in a classic sense. This is what the first four weeks at my first job looked like back in the 90s. ! 40 feet of dot-matrix printer paper, Steelcase cubicle dividers, khakis. Wow, I’m dating myself. ! So what I’d do back then is mark up code that didn’t look right, then pass it off to other programmers for fixing.
incorporating GitHub. ! One person makes a series of git commits on a branch, then bundles them into a pull request. ! Team members leave comments, code gets cleaned up, the branch is merged. ! So obviously we’ve improved.
up. ! Compared to GitHub pull requests, they’re faster, more direct and avoid those moments where you’re stuck wondering about sarcasm on the internet. ! But if you’ve gone down the road of reviewing code in person, you might have experienced tension or awkwardness. ! It could probably be better.
pairing with someone more senior, code reviews sometimes feel like judgment. ! Even pair programming, the most high-bandwidth form of programmer interaction, can’t stave off that intense feeling. ! Have you ever felt this way?
going to simulate a code review. ! There are two roles I’m going to talk about: ! *Reviewer *Author ! For this example: ! *I’m going to be the Reviewer. ! And that cat’s just going to hang out looking fuzzy.
a basic Backbone view. ! If you’ve written a Backbone app lately, you might appreciate some of what’s about to happen. ! If not, it’s just your average Javascript atrocity.
the Reviewer said first: ! *“You shouldn’t be using IDs here” ! Of all the days I’ve been on client projects in the last year, ! maybe a handful of them passed without hearing something like this.
talking about the merits of the code on the screen, the Reviewer is using objective facts, rules or information from outside the current discussion. ! Enforcing standards isn’t the most efficient use of time. ! Also, we’ve got Continuous Integration. ! Build failures are annoying, but the upside is that there’s no judgment.
Sonar) •Test Coverage (Blanket.js) INSTEAD OF BEING RIGHT Consider adding these tools: ! *If formatting comes up a lot, fork a Style Guide. ! *Add linters if code just doesn’t look right. ! *Add CodeClimate or Sonar if complexity or big methods need to be called out frequently. ! *If testing is important to your team, and tests aren’t being added, add a code coverage tool. ! Settings files don’t feel judged.
my brain immediately goes on the defensive. ! In the best of times, I’ll try to think of all the weird edge cases. ! In the worst of times, I’ll try to justify my code by saying something like “well, this is just an experiment.” ! As the Author, this doesn’t build a lot of confidence.
you show me what you mean?” Here’s a better approach. Just ask the Reviewer: ! *“Can you show me what you mean?” ! This lets the Author establish rapport with the Reviewer. ! The Reviewer feels trusted: they have space to explain what they’d like to see in the code. ! More importantly, the conversation moves away from the Author and back towards the code on the screen.
looking at this, we can see ! *automatic semicolon insertion ! *what seems to be a Heartbleed-style if-statement ! *possibly jQuery issues? ! ! The Reviewer chose to respond in a very particular way: ! *“As a junior programmer, you wouldn’t understand that this isn’t idiomatic JavaScript”. !
that this isn’t idiomatic” “What changes should I make so that this code is more idiomatic?” However, the Reviewer might be trying to say something valuable and choosing the worst way to say it. ! As the Author, we can steer the conversation away from personal comments and back toward the code with a simple question. ! *“What changes should I make so that this code is more idiomatic?” !
can we make this better?” ! Might not seem like a terrible question when it’s written down and we’re looking at it up on the screen. ! In the moment, remember, something happened. ! When I was talking with a consultant I work with, we came up with a pretty clear motivation: the Reviewer wants to guide the Author using Socratic questioning.
Author wrote this code, and the code review itself can imply that what’s there must be bad somehow. ! In deliberately hiding expectations, the Reviewer is creating a gulf that the Author needs to bridge. ! Pressure is put on the Author to come up with the correct answer. ! That’s combined with the Reviewer’s knowledge of the code’s inadequacy.
of being open to feedback during the code review, it’s easier to just stare out the window. ! The hard part here is, frustratingly, detecting when you’ve tuned out.
better?” “I feel confused about what that means. Where should we start?” The best way to re-engage with the Reviewer is to just talk about it: ! *“I feel confused about what that means. Where should we start?”
second. ! Code review is very formal, even to the point where people write books and give talks about it. ! We even use forms of code review for interviews, like white-boarding and pair programming. ! As we’ve found out, getting your code reviewed can sometimes be kinda nasty. ! So how do you know when you’ve had enough and your brain is melting down?
you and your coworker are just staring at the code, avoiding eye contact, not talking, then something is definitely up. ! What I notice is that I’m in this silent moment, and I’m not really sure how long I’ve been there.
from the situation after you come back from a break. ! If the Reviewer isn’t backing off and you’ve had enough, it’s time to call it a day. ! There’s something you can say here, too. ! *Let’s pick this up again tomorrow ! After that, you can go home or work on something else, but the code review is definitely over.
given you a bunch of tools for recognizing when a Reviewer is going too far. ! *Being right, an appeal to an external authority ! *Generalizing, the use of absolutes ! *Labeling, the act of excluding the Author from the engineering group’s inner circle ! *Playing the guessing game, getting the Author to exclude themselves
There are signs that you need to take a break: ! *Physical discomfort ! *Silence ! *Exhaustion ! There are other signs of physical stress than what’s up here, and you know your body’s language better than anyone else. ! These are just what I notice.
•Self-directed commentary •Avoid “you” Finally, there are some ground rules during a code review that both the Author and Reviewer should follow: ! *Talk about the code on the screen ! *Use self-directed commentary, sentences that begin with “I feel” and “I think” ! *Avoid talking about the other person, specifically be aware of the word “you”
of behaviors and practicing, but you probably won’t notice changes right away. ! It’s just like with meditation or yoga. ! When you’re better at it, you’ll know because it’s easier than it was six months ago.