Skip to main content

Pair Programming: How To Do It Right


Pair programming is an XP practice of putting two people in front of a computer, and having them program together. If you haven't seen it work before, it sounds wasteful. It is wasteful if you have one person writing code while the other passively watches, but there are some practices that make it a lot more valuable. When done right, I consider "paring" to be vastly superior to solo programming.


The way I have done pair programming goes hand-in-hand with test driven development. Here are the techniques I have used.


Ping-Pong Pairing

This is a beginner technique. It can get you in the groove for a day of pairing, and it's also useful as an introductory technique to pair programming.


Here is how it works:
  1. Developer A: write a failing test
  2. Developer B: make the test pass
  3. Refactor together
  4. Developer B: write a failing test
  5. Developer A: make the test pass
  6. Refactor together
  7. Rinse and repeat
The idea is to make a game out of it. Write the simplest possible piece of code to make the test pass, and do so as quickly as you can.


Navigator / Driver

Notice that this isn't "Observer / Driver", as I have sometimes seen it described. I don't like "Observer", because it implies a passive role. At it's best, the person who is not writing code should feel like they are working harder than the person on the keyboard.

This is an intermediate-to-advanced strategy, and the way that pair programming works in a high-functioning team. The roles are:

Navigator
  • Thinks strategy: "What do we need to test?"
  • Keeps the overall objective of the story in mind.
  • Keeps track of potential refactorings along the way.
  • Does NOT tell the Driver what to code.


Driver
  • Thinks tactically: "How do I write this test?"
  • Focused on the next small step.
  • Keeps up a dialogue with the Navigator, describing what he/she is doing.

The key is to switch roles periodically. You don't want to do it too often, or you risk getting out of a good rhythm. You don't want to do it too seldom, because it's too easy for the Navigator to become disengaged.
Good times to switch are when:
  • There is a change of concept.
  • "I need a change."
  • A timer beeps (this isn't a bad way of starting with this technique, but not best for long-term).
Post a Comment

Popular posts from this blog

Agile Performance Management: Why Performance Reviews Suck

Many thanks to Mary Poppendieck, who wrote about this topic in 2004, and proposed a comprehensive solution.  She is the inspiration for much of my thinking on this subject.  She is also a better writer than I am a cartoonist.


Performance reviews suck.  I don't know of anyone who goes into their appraisal without some trepidation.  Your boss is guaranteed spring some surprise criticism on you that is ill-informed or misses the point as you see it.  It's a real challenge not to get defensive about that.

The only thing that makes your own performance review suck less is having to give them.  As a manager, I have dished out quite a few, and some of them went pretty badly.  (To the people at my first management job: Thanks for helping me learn how to get better at them.  Your sacrifice was not in vain.)  Since then, receiving one isn't nearly as gut-wrenching, if only because I try to make it easier for the guy on the other side of the desk.  I've been there, and I know how …

Do. Not. Optimize.

You've probably heard this quote before:
Premature optimization is the root of all evil.
 - Tony Hoare
Speculative optimization is always wasted time.  In the absence of an actual performance problem, you're just burning time that could be better spent on refactoring your code to make it clearer.  This is exacerbated because performance-optimized code is usually harder to read than code which hasn't received such treatment.

Here is what you're doing when you optimize:
Adding code that now must be maintained.Obfuscating the existing code.Spending time writing code that doesn't add value. But what's that you say?  You have the experience and know-how to decide when optimization is needed?  Maybe, but probably not.   The people at Sun and Oracle may or may not be smarter than  you or me, but they certainly know more about optimizing Java bytecode than we do.

For example, some people think that having a large number of classes is slower than the alternative.  This …

Developer Skills: Drawing

You aren't a good developer if you can't draw. Fortunately, if you're a human, you can.  Drawing isn't an inborn talent, it's a technical skill that can be learned.  Write the previous sentence on a piece of paper to prove it to yourself.



There.  You just drew a whole bunch of letters quickly and (hopefully) legibly.  Words are a complex set of shapes that need to be drawn in a particular sequence to have meaning.  It's the same basic skill you use when drawing non-character shapes.

Drawing isn't a binary skill that you either have or do not have.  It's a continuum, and even at the shallow end (people with barely-legible handwriting), you have enough of it to communicate ideas visually.

So that changes the top line of this post to:
You aren't a good developer if you don't draw. Visual communication is much more powerful than text.  (This study found 65% retention over 3 days for images vs text.)  We also absorb visual information much faster th…