Thoughts on Pair Programming
Ahhh, probably the most controversial subject in development. I don’t know of any single issue that is more likely to get people riled up, either for or against it.
My experience is pretty simple. I’ve never done pair programming “full-time.” But, like most programmers, I’ve done it at times - working with another programmer over a problem.
When I’ve done that, I’ve generally found that a few things happened:
- My knowledge increased
- Hopefully, the knowledge of the other guy increased
- We both understood the system better
- We generally produced better quality code than I was used to seeing from either of us, individually
- We remained more highly focused
There’s been a number of studies done on pair programming. Most of them use similar methodologies, and reach similar conclusions. I’ll dig up references later.
In general, they take developers or students, and divide them into two groups. One of the groups will pair up and work on a project, while the other group will approach the project individually.
In general, these projects are rather small. In one experiment, they were class assignments, over a period of time.
The results generally found were that the pair took less clock-time, but more man-hours to complete the task. Generally, the results from pairs were of higher quality.
One particular study continued the experiment over time, and found that the tax on man-hours dropped from 40% at the beginning, to only about 15% at the end of the experiment.
Now, that’s pretty impressive by itself. If a project would normally take 40 hours for a single developer, and with two, you can get it done in 22 hours and with higher quality, I think that’s a win.
But, I think that the experiments described are testing the wrong things.
I see the real benefit of pair programming not in coming from initial productivity, but from the ability to sustain productivity over time, and to allow higher levels of scaling.
One effect noted was that for pairs to become highly effective, it took some amount of time for both the developers to get used to pair programming, as well as to get used to each other. When doing an experiment on a small or micro basis (projects taking <1 day to complete), the initial cost of this can easily outweight any benefits.
Secondly, one advantage that I see is increased knowledge of systems. By pairing, especially if pairs are not static, developers will work on multiple areas of the project, and will gain understanding of the “big picture” of what they’re doing, rather than their isolated area. This should increase overall quality, as well as remove the “hit-by-a-bus” category of risks. When working on small projects that can be completed in under a week of work, this is mostly irrelevant.
Third, by pairing developers, you will remove some level of the communication tax. Given four developers, if they work individually, they must all coordinate. If they are paired off, you now only have two groups that need to coordinate, instead of 4 individuals. Because the “individual” developers worked as exactly that, they had zero communication tax. Comparing paired developers to two developers collaborating as individuals would be an interesting metric.
Fourth, maintenance is very important. While “passing tests” is an important measure of quality, the ability to maintain and expand code is also extremely important, if hard to measure. If pairing increases quality, then this additional quality should (in theory) allow code to be more easily changed in the future - especially when a larger number of developers have insight into it. Again, on small projects, this benefit is unimportant.
None of these benefits can be measured on toy or small projects.
So, how would I design a pair programming test, in an ideal world?
I think you’d only need to change a few things.
First, projects need to be somewhat longer - at least 40 hours to completion. And that is minimum.
Secondly, to be fair, the test needs to compare equal-sized groups of developers to each other, working individually or in pairs. In my experience, I’m not sure that adding a single additional developer actually increases productivity, but this is a more realistic comparison.
And last, ideally you’d want to scale out even further - four developers or more, working in pairs, against a team of the same size working as individuals. Generally, in a realistic environment, the question is not “should we hire twice as many developers and have them pair?” The typical question is “we have this many developers - should they work alone, or in pairs?”
I honestly don’t know how these results would turn out. But, I suspect that they’d turn out very well for pair programming, especially if combined with other practices (such as TDD).