Home Contact us
Home » Resources » A case for pair programming

A case for pair programming

by Sergey Andrzeevski

Dec 12, 2006

While it does not work equally well for everyone, it works extremely well for most who give it a try.

Pair programming is one of the most unorthodox practices of Extreme Programming and is harder than most to digest for people new to XP. Over the last 4.5 years, having managed dozens of XP projects, I have come to appreciate pair programming a lot, and would like to share some of my observations about this practice.

Furniture challenged

While adopting pair programming caused our developers to rethink many things, one of the other things it did it also forced the company to buy larger desks. Testers and the PM were OK and got to keep their old desks: you have not heard of pair testing or pair project management (now that would be something else). We also had to rearrange our working space to make sure that all project team members worked in the same room: there is nothing worse than a frustrated developer who has to run from one room to another to switch pairs. We even considered getting special chairs (see picture) but rejected the idea as too extreme (yes, there is such a thing as too extreme, even for an extreme shop like Exigen Services!).

double armchair

“Pair what?!”

Once the furniture problem was out of the way, we had to deal with, ehr, people. The people who simply didn’t see why they should do this ridiculous thing – sit at the same keyboard with someone else. Some engineers develop an outright aversion to the practice, they simply cannot do it. In fact, I believe the motivations of the objections to pair programming are a very interesting topic in and of itself, and could make for a great article. I won’t spend time on it here, but will just quote an article in Computerworld I once read: “You can't sit any two programmers down at a terminal and expect good results, because it flies in the face of why many people program. Programmers consider themselves masters and artists, and if you have two artists at the same palette, they're going to fight over the brush.”

We never forced anyone to do it, but we have asked people to give it a try. Most of those who did quickly saw the light and joined me in advertising thee practice to the rest of the team by stressing the following benefits:

  • A pair turned out reliable code that was more reliable of the instant peer review that enabled them to catch errors early
  • Pair programming perfectly supports collective code ownership, which had proved a very important success factor in projects over time
  • Better focus while working in pairs. This one is a biggie: so many folks reported that they simply felt uncomfortable responding to distractions (such as an IM message that popped up in the corner of their screen, or a sudden urge to check the movie times for the upcoming weekend, or to take an IQ test) while actually working on something with a colleague. As a result, people’s productivity soared!
  • Working in pairs can actually be more interesting – you get to run ideas by one another, pick your partner’s brain on the go, and cooperate while solving complex (or not so complex) tasks
  • Pair programming is an invaluable training vehicle for new hires (more on that later).
  • This actually works the other way too: there is great satisfaction in teaching someone else, in sharing the little gems of knowledge and experience you have accumulated through your work. Some senior guys get some kick out of pair programming too.

Waste of Time… Not

One of the common objections to pair programming is, “But this is a waste of time! Put each of us in front of the computer, and we will produce twice the amount of code in the same number of hours” Well, on the surface, it does seem like that is exactly the case; but only on the surface. If all you have are small, relatively simple and independent programming tasks, you can actually finish them faster working separately. However, imagine a big, complex project with thousands of mutually connected tasks, plus take into account additional time needed for research, design, coding, debugging, fixing, refactoring, rework… you know what I’m saying? In this situation, surprisingly, pair programming yields equal or better speeds and higher quality of code than the same developers working separately. Most of the times, developers found this argument convincing.

Setup

So, how did it work? During the morning standup meeting we defined User Stories and tasks to be completed during the day, and developers split into the pairs. As a project manager, I usually did not assign pairs, the process was self-organized. Factors affecting people’s decisions included developers’ experience in specific areas, knowledge related code, and human compatibility. Sometimes, a technical lead would advise a pair combination, especially when dealing with rookies. If a pair started working on a certain User Story, they worked on it together until it was completed. While we did not strictly enforce pair programming, I believe developers worked in pairs 60-70% of the time. It was interesting to observe how a stronger developer would usually work in pair with a less experienced one. Sometimes though we put two stronger guys (or gals) together – usually to tackle a particularly difficult task, or to facilitate knowledge sharing. Sometimes, we would also put to less experienced programmers in a pair to appreciate their initiative.

Perfect For Training

Not only do the developers get to share their knowledge of the system in question; they can actually significantly advance their knowledge of a particular technology quite quickly. This is achieved by putting a less experienced engineer in a pair with someone more experienced. Pair programming has helped us tremendously to flatten the learning curve and bring people up to speed much more quickly.

I am not saying that you can do any project with any number of inexperienced developers. On a typical XP team in Exigen Services, we have 7 people (4 developers, 2 testers, and a PM). Actually, just having 2 really experienced developers is enough in most cases to move the project forward with reasonably good speed. Roughly, at least half of your team should be experienced and familiar with the codebase and the technology, while the rest can be less experienced; what they need is the general ability and a desire to learn new things. Pair programming empowers newcomers to show great progress very quickly.

(A note to management: as an added benefit, pair programming enables the company to evaluate an employee’s real skill level in a matter of days, as opposed to weeks and often even months in traditional development.)

Exceptions

As much as we programmers hate exceptions, they are a contestant attribute of real life, and pair programming is no exception to that rule. Pair programming does not work equally well for everyone; in fact, for some people it does not work at all. Sometimes it’s character, sometimes it’s the inertia of habit. In my experience, most often the person to completely reject pair programming is a guru with lots of experience and seniority in the organization, great knowledge and skill, and little or now interest in teaching or training others. Some of these kind of guys were able to work successfully on XP teams, sticking to tasks like DB design or research were pair work is less important. Sometimes they moved to traditional (non-Agile) projects where communication between team members was not emphasized.

Guideline, Not Rule

Of course, pair programming is optional, but I have seen it work too many times in too many was, and I am sold. I hope I’ve made my case and was able to peak your interest. True, individual programming works fine for many tasks, particularly for:

  • very simple or standardized tasks
  • research
  • debugging
  • defect fixing
  • investigating requirements & other documentation

However, no one can deny that when you leave the office and stop at your favorite bar for a beer or two after a hard day at work (no, we don’t do much overtime – 40 Hour Week, remember?), a drink just feels better when you have good company!