Pair Programming is Awesome
November 2009
I've been meaning to write about this for a while. Pair programming is
awesome. I was a huge skeptic when it was first pitched to
our team, but after trying it a few times, I was completely sold. It makes
you more productive, produces better code and is just more fun all around.
I'm know there has been tons of stuff written about this, but when I read
it, I was so skeptical that I thought all those authors were crazy. But you
know I'm not crazy. So I'm going to tell you why its great.
Photo from
hassi on Flickr.
Benefits of pair programming
Not convinced? How come? I already said it was awesome
(and I put it in bold). Here are some benefits --
- It keeps you focused. If you're anything like me, you
probably have a tendency to drift when you hit a stopping point. Maybe
check some e-mail or read your
favorite blog.
Not anymore.
- It helps when you get stuck. Its easy to spend a lot
of time trying to figure out something that you're unfamiliar with. It
always helps to have someone to discuss it with without having to feel
bad for interrupting your co-workers all the time.
- It avoids stupid mistakes. Have you ever spent 30
frustrating minutes trying to figure out why your change isn't showing up
in the output, only to realize that you forgot to hit save? Yes, yes,
you have. Your partner is likely to notice those things before you
spend unnecessary time pulling your hair out.
- It produces better code. It's less tempting to take
shortcuts, write unreadable code and "forget" to test things when you're
working with someone.
- It's the best way to learn a new code base. The best
way to get someone up to speed on a project is to have someone pair
program with them. They'll spend less time digging around outdated
documentation and more time contributing. I've effectively pair
programmed with people outside my team who knew absolutely nothing about
the project coming in.
- Its more fun. This one really depends on the people
you're working with, but its definitely a big upside.
How to set up a pair programming workstation
The set-up is really, really important. Both people need equal access.
You'll need:
- Two keyboards
- Two mice
- A long, straight desk (no weird angles)
- A giant monitor
It's key for each person to have their own keyboard and mouse so that no one
is just sitting there passively watching the other person type.
How to pair program
Now that you've got a sweet workstation set up, its time to actually do it.
This part is easy, just start writing code. Switching off can be a bit
tricky at first, but soon it'll become seamless.
If you're using Test-Driven Development (writing a test before writing a
feature), you could have one person write a test that fails, then have the
other person make the test pass and write the next test. Its an easy way to
make sure you're switching off regularly.
One of the big advantages is that it's easier for something to do or fix
something than to spend time explaining it. Notice that something is
spelled wrong? Fix it, you have your own keyboard. Have an idea for how to
do something? Just write it and let the code speak for itself, instead of
trying to explain what you're trying to do. You can always delete or edit
it as necessary.
Potential Downsides
- It could take longer than two people working independently.
This is true, but I'd argue only if both people know exactly
what they're doing. More often than not, when you're working on
something new or complex, pair programming will be faster.
- You could end up hating your co-worker after spending so much
time with them. This is true too. Definitely switch things
up often to avoid this.