Page 99 -
P. 99
Pair Programming
Pair programming is a technique in which two programmers work simultaneously at a sin-
gle computer and continuously review each others’ work. Although many programmers
were introduced to pair programming as a part of Extreme Programming (see Chapter 12),
it is a practice that can be valuable in any development environment. Pair programming
improves the organization by ensuring that at least two programmers are able to maintain
any piece of the software. Pair programming also helps programmers’ professional devel-
opment, because they learn from each other.
Pair programming is like having a continuous code review, without the extra time or
effort of holding individual code reviews. It encourages a redundancy among the team
members, and everyone is cross-trained on various parts of the code. Junior people can
more quickly learn directly from senior people when they are paired together. While it
may seem that assigning two people to a single programming task could be inefficient, in
fact, productivity often increases. It takes somewhat less time to perform each task, as
there are often gaps where one person is “tapped out” and the other can take over. More
importantly, the resulting code is of very high quality, so there are far fewer mistakes to go
back and fix.
One useful benefit of pair programming is that people tend to write better code when they
know that someone else will be reading it. They cut fewer corners, spend more time mak-
ing the code readable, are more likely to include comments where necessary, and refactor
more often.
In pair programming, two programmers sit at one computer to write code. Sometimes
they share a single keyboard and mouse, although it is possible to get special hardware or
cables that allow each programmer to have his own. Generally, one programmer will take
control and write code, while the other watches and advises. But different pairs of people
may discover their own dynamic: for example, some pairs will take turns at the keyboard,
while others will designate one person as the typist (if one person types significantly faster
than the other).
It’s straightforward to implement pair programming in any development team—just
choose two programmers who are willing to give it a shot, and have them work together
at the same computer. However, it’s important to remember that, like any programming
technique, pair programming is a skill that improves with practice. Some benefits can be
realized almost immediately, but there is no substitute for years of experience. But, like
any other programming skill, the only way to get experience is to practice.
While efficient pair programming is a skill that requires practice and patience, there are
some useful tips that make its initial adoption easier. People will be less resistant to a
change if their first experience with a new technique is positive. One way to help guaran-
tee this is to pilot pair programming on a low-risk portion of code. The project manager
should choose one where the scope and requirements are well understood going into the
project, and where success is easily measured. Both members of the pair assigned to work
REVIEWS 91