Who's Your Coding Buddy?

February 25, 2009

I am continually amazed how much better my code becomes after I've had a peer look at it. I don't mean a formal review in a meeting room, or making my code open to anonymous public scrutiny on the internet, or some kind of onerous pair programming regime. Just one brief attempt at explaining and showing my code to a fellow programmer -- that's usually all it takes.

This is, of course, nothing new. Karl Wiegers' excellent book Peer Reviews in Software: A Practical Guide has been the definitive guide since 2002.

Peer Reviews in Software: a Practical Guide

I don't think anyone disputes the value of having another pair of eyes on your code, but there's a sort of institutional inertia that prevents it from happening in a lot of shops. In the chapter titled A Little Help from Your Friends (pdf), Karl explains:

Busy practitioners are sometimes reluctant to spend time examining a colleague's work. You might be leery of a coworker who asks you to review his code. Does he lack confidence? Does he want you to do his thinking for him? "Anyone who needs his code reviewed shouldn't be getting paid as a software developer," scoff some review resisters.

In a healthy software engineering culture, team members engage their peers to improve the quality of their work and increase their productivity. They understand that the time they spend looking at a colleague's work product is repaid when other team members examine their own deliverables. The best software engineers I have known actively sought out reviewers. Indeed, the input from many reviewers over their careers was part of what made these developers the best.

In addition to the above chapter, you can sample Chapter 3 (pdf) courtesy of the author's own Process Impact website. This isn't just feel-good hand waving. There's actual data behind it. Multiple studies show code inspections are startlingly effective.

the average defect detection rate is only 25 percent for unit testing, 35 percent for function testing, and 45 percent for integration testing. In contrast, the average effectiveness of design and code inspections are 55 and 60 percent.

So why aren't you doing code reviews? Maybe it's because you haven't picked out a coding buddy yet!

Remember those school trips, where everyone was admonished to pick a buddy and stick with them? This was as much to keep everyone out of trouble as safe. Well, the same rule applies when you're building software. Before you check code in, give it a quick once-over with your buddy. Can you explain it? Does it make sense? Is there anything you forgot?

I am now required by law to link to this cartoon.

the only valid measurement of code quality: WTFs per minute

Thank you, I'll be here all week.

But seriously, this cartoon illustrates exactly the kind of broad reality check we're looking for. It doesn't have to be complicated to be effective. WTFs/minute is a perfectly acceptable unit of measurement to use with your coding buddy. The XP community has promoted pair programming for years, but I think the buddy system is a far more practical way to achieve the same results.

Besides, who wouldn't want to be half of an awesome part-time coding dynamic duo?

Batman and Robin

That's way more exciting than the prospect of being shackled to the same computer with another person. Think about all the other classic dynamic duos out there:

Individuals can do great things, but two highly motivated peers can accomplish even more when they work together. Surely there's at least one programmer you work with who you admire or at least respect enough to adopt the buddy system with. (And if not, you might consider changing your company.)

One of the great joys of programming is not having to do it alone. So who's your coding buddy?

Posted by Jeff Atwood
132 Comments

lonely codeman

:( on February 27, 2009 10:24 AM

I championed the institution of a permanent check-in partner system at my current place of employment after seeing it used intermittently at my previous one.

Unlike pair programming, it's extremely easy to get people on board with it. It rarely amounts to more than about 3% programming time investment (assuming a day's work and a 15-minute review).

The obvious benefit is that bugs get caught before check-in, but I believe that the distribution of knowledge that check-in reviews promote is a more important benefit in the long term. Check-in partners learn good techniques from each other, maintain coding standards, and learn what code is actually going into the project.

So far, at my current shop, everyone who's been introduced to the idea likes it, which is pretty remarkable for a piece of process.

Hamilton-Lovecraft on February 27, 2009 10:30 AM

Pair programming is not necessarily an onerous regime. I think the key is to not make anything a regime.

I personally like the open source development model, with developers more or less submitting patches to the project owners. It's a good way to keep the code clean and to make the best use of the best people.

matt mcknight on February 27, 2009 10:47 AM

There is even a recent ms-research paper on this topic.

http://research.microsoft.com/pubs/75108/esem-begel-2008.pdf

Ben L on February 27, 2009 11:25 AM

It's hard to do a code review if there are no published guidelines or standards. Each company should have this document, which itself must be updated and reviewed regularly.

Everyone wants to be code cowboy, but best practices do exist and not everyone on a team can have it their own way. The code belongs to the company, after all.

And, each company needs someone to manage the devs. They don't need to be the best coder, but they must know how to settle disputes and pick the best path, and be able to tell the coders to shut up, it time to move on.

Steve on February 27, 2009 11:25 AM

It's hard to do a code review if there are no published guidelines or standards. Each company should have this document, which itself must be updated and reviewed regularly.

You're trolling, right?

If you aren't, then I'll just say that code reviews are supposed to be informal - no guidelines beyond look at the code and make sure the guy checking it in can explain what it does.

chris on February 27, 2009 11:41 AM

@chris: nope.

But implying that all code reviews are informal with no guidelines beyond having someone explain what it does is exactly the opposite of what I've seen work.

Steve on February 27, 2009 12:05 PM

well code reviews aren't the only thing, it's just a useful check on keeping bugs out of the codebase.

chris on February 27, 2009 12:52 PM

Rihanna and Chris Brown

Theo on February 28, 2009 1:39 AM

Hello??? Ren and Stimpy? (especially appropriate because most of the time you are saying to your partner, Stimpy, you Eeeediot!

Spongebob and Patrick
Oscar and Felix
Solid Snake and Raiden
Black Mage and White Mage
Aragorn and Legolas
Kirk and Spock (are you out of your Vulcan mind?)

I Am 8 Bit on March 2, 2009 1:09 AM

I absolutely loved the cartoon about code reviews showing wtf/minute, it is just as funny as it is true. A colleague of mine happened to take a look at it and did not find it funny at all. Actually I had to explain the cartoon to him. As you might imagine he is one of those who writes a lot of wtf code. At my workplace there are few of us that understands that cartoon so finding a coding buddy, as important as it is, is not an easy task where I work. I think i will settle for a rubber duck that I can talk to when I have a need for feedback. That way I will be guaranteed to not get the usual crappy answers :)

JH on March 2, 2009 7:08 AM

You can get really valuable lessons with this simple practice.

We do this religiously in my team (we try to find the time for it even if apparently there is none).

Right now my coding buddy is a former trainee (he finished serving his time like a year ago) and believe me, I have got great insight of things I did not considered, potential bugs, hard to read code, event method/variable naming corrections from him. So even if you feel like a all seasoned programing veteran, there is always room for improvement if you are humble enough to take advice from your peers regardless of their credentials or seniority.

Chepech on March 3, 2009 7:01 AM

Simon Nicol, I feel bad for you...

Programing is not a path that you can walk alone... at least not a lasting pleasant one.

70% of a good programmer skills are social, not technical.
I have worked in the game industry too and I find no resemblance of it in your words. I guess I never worked with someone you thinks we are demoted godlike rock stars. All the people I have worked with (including myself) feel more like mercenaries how enjoy it so much that could do it for free, but why do it for free if you can make a profit... with the exception for idealistically OpenSource projects.

Chepech on March 3, 2009 7:13 AM

And what for this :
http://blogs.tedneward.com/2009/02/22/As+For+Peer+Review+Code+Review.aspx ?? Can be that we developers do not have good and scientific measurement tools? Is possible that Computer Science is a child(prodigy) engineering branch in comparison to other fields such as Electronic Engineering for example?

Indrit on March 3, 2009 12:19 PM

I work on a development team consisting of about 25 active programmers, working on a very large insurance application that has about half-a-million lines of production Smalltalk code and probably a similar amount of unit and functional test code.

For over 5 years we've had a designated team of 5 or 6 developers acting as part-time code reviewers. Someone from this team must review every line of code - including the unit and functional tests - before it gets released to the current shared development stream.

This Code Review team has weekly meetings where issues identified during reviews performed in the previous week are discussed and shared within the team. We've seen a substantial improvement in overall code quality during the last 5 years but one of the big payoffs has been that this Code Review team has been exposed to pretty well all major aspects of our complex application. This allows us to be very effective in identifying common problems like duplicated code or code not being implemented in the ideal locations. We're also well-placed to see opportunities for framework changes that other developers, focusing on solving just the problem-de-jour, might miss.

We have had excellent support from our managers but the success of our Code Review process has been predominantly due to the efforts of the development team itself.

Richard on March 4, 2009 6:56 AM

How about Sherlock Holmes and Dr. Watson :)

kodeninja on March 4, 2009 9:20 AM

This only works if done properly, and is done early in the process.

A place I used to work at, code reviews were done after you've done all of your work and it was supposed to be correct and accurate. If there anything they didn't like or you'd make some insane decision (because you weren't supposed to figure it all out yourself and not talk to anyone else) the senior team would complain to management.

Former Borg on March 8, 2009 4:07 AM

As a non native English speaker I've been calling this pal programming instead of pair programming for years =)

90% of my everyday work consists of test-driven pair programming developing. I do really little code without my current pal, and I'm getting lazy about it. I enjoy every minute we spend sharing programming achievements and frustrations with someone.

So here is a thought: what is more efficient?

- Having two programmers doing the job of one, but ensuring better code thus less debugging time.
- Have each one on their code and do some code review sessions.

Obviate childish pairs of lazy irresponsible programmers expending more time in youtube than in their code.

(I would add Asterix and Obelix to that list of famous couples)

Txau on March 8, 2009 6:33 AM

You forgot about Hardcastle and McCormick

Marthinus on June 11, 2009 10:56 AM

Very much disagree with Max - reviewing other people's work is one of my responsibilities as one of the more experienced team members, and I'd be seriously concerned if it looked to me that they were getting careless, expecting me to save them. If the coder is doing their job properly, the reviewer shouldn't be doing anything more than suggesting ways something could be done better, not ways it's been done wrong.

Simon on February 6, 2010 11:13 PM

I think you left out B.J. and the Bear, Smokey and the Bandit, Tom and Jerry, and Butch Cassidy and the Sundance Kid...

Jason Punyon on February 6, 2010 11:13 PM

Yeah self reviewing the next day does seem to work quite well although I am sure it doesn't hurt having another pair of eyes.

Leon Sodhi on February 6, 2010 11:13 PM

the buddy system on school trips is i'm sure at least as much about making it easier for the teachers to be able to count the children

John Ferguson on February 6, 2010 11:13 PM

For the UK based programmers there is

Morecambe and Wise
Little and Large
Bill and Ben
French and Saunders

to name a few

Jon on February 6, 2010 11:13 PM

For those review resisters they need to be pointed to the analogy that writing code is like writing a book or even producing a scientific article. An author will get the book edited before publication, a scientist will get their work peer-reviewed before publication.

Jon on February 6, 2010 11:13 PM

My team recently took on peer review as part of our general approach to process improvement, and the impact on quality it has had is phenomenal. It uncovered some long standing problems with an approach one developer had used for a couple years, brought the team closer together, and gives everyone an opportunity to learn from each other.

While the initial perception from outside the team doing the reviews was that productivity was lower and a lot of time was spent doing these reviews, at the end of the release cycle the time has been more than recaptured in reduced defects and quicker time to complete regression testing.

If you plan to do this with a team, there is a great tool from Atlassian called Crucible that I would highly recommend. It makes the review process much easier, and can be tied into each CVS commit.

Jason on February 6, 2010 11:13 PM

Karl's book is excellent and anyone wanting to implement a whole code review process should get it.

My book on lightweight peer code review (free at http://codereviewbook.com) adds more data to the picture, specifically around less formal kinds of review like just buddy-checks (as you talk about), email pass-arounds, tools, and pair-programming.

It turns out a lot of the techniques in Karl's book are unnecessary for a good ROI. Meetings, for example, take a ton of time and don't contribute much to uncovering bugs.

Jason Cohen on February 6, 2010 11:13 PM

Who is my coding buddy?

Cheryl Burke.

Jon on February 6, 2010 11:13 PM

Crumbs.

I've been writing video games for a long time. The words 'code review' to me mean allowing someone to look over my work and then steal all my great ideas.

It means handing over all the clever techniques that no-one else knows how to do and sacraficing being one of the world's leading programmers and handing out stunning inspiration on a platter to anyone who wants it.

The trouble with all this code review crap is that programmers used to be held in awe, now adays the rank of programmer has been demoted from rock-star-god, film-star, super-genuis to the rank of someone working in a corner shop, any old Joe, Indian sweat shop worker, Nike Trainer maker.

Big business, greed and the lack of self respect has taken the status of programmer to nothing special. Multi billion pound companies can kiss my arse, they're only as good as WE made them. As far as I'm concerned they cal all F* OFF!

Fortunately I have a new project in mind, that will make the shit they call AI today look pretty embarrasing.

Only the best need apply to join the team.

P.S If you haven't heard of me as a programmer, don't bother applying - lol

http://caspianit.co.uk

Simon Nicol on February 6, 2010 11:13 PM

you westerners....

Miyuki and Natsumi

I'm not going tell much, just... not another cop show :-)

On a serious note, I knew about the power of pair programming and work buddy a long time ago. If anything, the most prominent effect I have experience is how working with somebody else in real time inherently has me _paying_attention_ to the matter at hand with such focus. Left alone, my mind tends to wonder and think about other irrelevant topics (read: procrastination and distraction).

And then now, the real problem - it is just too dang difficult to find a buddy who is interested in the same topics and activties as I am. Even individuals who are self-motivated and competent have their own interests and schedule to attend to.

Aaron Seet on February 6, 2010 11:13 PM

They're still great things to have, though, and overall I think they really do improve things. Reviewers often see things that I never would have, *even if the reviewer has less experience coding on the project than I do*.


the cash code

Dianehall on June 1, 2010 11:44 PM

A complete team of programmer can only be able to complete task. Because a project does not involve programming only, i has to follow business rules and many other ethics. All this can only be happen when team work will be done. 360 degree feedback

BLOG POST on May 31, 2011 9:21 AM

«Back

The comments to this entry are closed.