In the comments for my review of “The Art of Agile Development” an old colleague asked me a few questions about Pair-Programming, one of the key tenets of XP (which the book advocates). My response so was so long and detailed that I felt it deserved it’s own post.
My current job is the first one where I’ve ever pair-programmed. I actually recall interviewing for it, and I was asked if I had pair-programmed before. I said sure, occasionally I would pull another developer over to my desk to help me and we’d sit together to figure it out. This apparently was a decent enough answer to the question that I got the job, but now that I’ve been pair-programming nearly full-time for five months, I’ve determined that what I was doing before was definitely not real pair-programming.
When I first heard I’d be pairing at the new job, I was a bit apprehensive and skeptical. Do I really have to sit next to some fat developer all day, 40 hours a week? When am I going to check my RSS feeds? What if the other developer is gassy or hasn’t showered? How am I going to listen to my totally awesome Death Metal if I can’t wear headphones? Will the other developer be constantly judging and correcting my code? Will pairing prevent me from hitting “the zone” where I’m just belting code out so fast that my fingers can’t keep up with my brain?
Over the last five months, I’ve found answers to all of these questions: “no,” “often,” “that’s rough,” “easily,” “sort of,” and “YES, but that’s a good thing.”
The Mechanics Of Pairing
The way pair programming works in practice is quite a bit different than I imagined it. I envisioned a day where I couldn’t escape the company of some other developer, constantly having eyes looking over my shoulder. I’m not a terribly social person, so the idea of interacting with a single human being all day was not my idea of a good time.
In reality, you don’t sit down at a desk with another person and work all day with them. You pair up for tasks.
So, once all of the stories for the iteration have had concrete tasks assigned to them, people pair up to do them. So a dev and I might pick a specific task and work on it together. Two other devs pick another task. My pairing partner and I sit at a big 30 inch monitor and work on the task (just that task) together. Generally when you pair one person is the “driver” and one is the “navigator” so one person is implementing code and the other is thinking of design implications, refactoring opportunities, or the “next step” for the task. If you get stuck or pause or just want to switch, you pass the keyboard to the other person and switch roles.
When doing Test-Driven Development, one of the things we do is called “ping-pong pairing”. So the other developer will write a test, then make it compile but fail. Then he passes the keyboard to me. I implement the feature just enough to make the test pass, then I write another failing test and pass it back.
When the task is done and code is checked in, the pair breaks up. Generally tasks only have 2 hour estimates (sometimes less) so you’re only pairing for the two hours. Then you pair up with someone else to work on another task. If a task is taking longer than expected, or the pair “goes dark” (meaning they aren’t talking) then you shuffle the pairings.
Between these tasks, you might go have lunch, or take a break from coding to watch a video on youtube at your desk, or check your RSS reader for a few minutes, or go take a walk, or go downstairs and play some ping pong or foosball. We take breaks often because getting away from the code for a few minutes helps keep a fresh perspective when you come back to the task. Physical activities like walking or playing ping pong help with blood circulation, which helps your brain.
It’s also nice to have an odd number of developers, which we do. This way, one person is working without pairing. Usually this person will work on a defect instead of a story, or they’ll work on a story where everyone understands what needs to be done for that part of the code. If you don’t feel like pairing or you need a break, you volunteer to be the odd man out for a task. When I first started pairing, I frequently volunteered to be the odd man out and work alone. Today, having been pairing for a few months, generally I try my hardest to avoid being the odd man out.
In an 8 hour day, I’m probably pairing somewhere between 4 and 6 hours noncontiguously. It’s important to have a good setup for it – big monitors, comfortable chairs, no corner desks (so that the devs can be side by side at the flat desk with the monitor between them).
Effectiveness
I see pairing work so well every day that I consider my career prior to my current job to have consisted mostly of wasting time. When I think back to all the code I’ve written for a job, I’m annoyed at how much less efficient I was then since I wasn’t pairing, and how much better my code and my products would have been if I had paired on them full time.
When you have a second person working with you, you find that you try harder to code well. You’re far, far less likely to be willing to apply duct tape to a problem, because someone else is working with you and he or she is more likely to object to the duct tape. If two people approve a hack and implement it, it’s almost certainly because it’s the right approach given the time constraints. If one person sitting alone decides to pursue a hack, it’s more likely to be a situation where there is a better approach.
Two people attacking a design problem together is easier than one person doing it. Your partner will think of things you don’t, and vice versa. In a non-pairing environment, you can always call someone to a whiteboard to help you work through a design issue, but when you do that you’re only calling for help when you know you need it. The times when you need help and don’t know it go unaddressed – and yet despite the fact that you need help, I guarantee that you’re coding SOMETHING and checking it in. It’s almost certain to be shitty code. The amount of time you spend trying to figure out “what’s going on here” or “why isn’t this working the way I expect” is severely reduced. I’m talking hours of debugging that literally turn into seconds.
Pairing also helps a great deal with collective code ownership. I don’t feel like there are any realms of the code that “belong” to any team member. You don’t have a situation where one person is the “expert” on a part of the codebase, since that person worked with someone else when they wrote it, and everyone likely shuffled around while it was developed. EVERYONE has seen that part of the codebase before, which means EVERYONE feels comfortable refactoring or extending it. This enables the team to perform improvements to any part of the code whenever they are working, which leads to technical debt being paid off very quickly. I often find myself shocked at how good the quality of the code is that we write and that we’ve written before. The product is ENORMOUS in code size, easily the biggest I’ve ever worked on, but there are very few areas of code that I would consider bad at all, and all of those are the earliest parts of the code that were written (and were written without pairing or TDD).
Pairing fosters a collective unity that I haven’t seen anywhere else. There are obviously issues and challenges, and there’s no denying that you’re producing fewer lines of code per day since only half your team is coding at any one point. I don’t consider that a bad thing, though (if you have two solutions that equally solve a problem, the solution with fewer lines of code is the superior one) because the QUALITY of the code that IS produced is so, so, so much higher.
Challenges
There are definitely some challenges to pairing. Pairing at a corner desk absolutely does not work at all. The developers need to be side by side, the same distance from the monitor (which needs to be large). All instances in my career that I thought were “pair-programming” were not, because we were at corner desks. The person further away was, as a result, not as actively involved in the code (moving chairs is harder than moving a keyboard over a few inches). This isn’t pairing, it’s programming with someone watching over your shoulder. It feels like you’re being watched, not like you’re working with a peer. It sucks. I’m so glad that this is NOT what real Pair Programming turned out to be.
We have a team area with individual desks surrounding the area, but with “pairing stations” in the middle of the room. I find myself at my desk so infrequently (by choice) that my friends on IRC complain I never say anything on the channel. A good pairing environment is crucial.
Hygiene can be a serious problem. If one person smells, it’s rough to sit with them. I find myself going back to my desk often and the code suffers for it. If you’re pairing, take a shower, and hold your farts for your next bathroom trip. Just do it, you filthy pig.
The biggest challenge for me personally was essentially mourning for the death of “Programmer Man”. Programmer Man is how I think of myself when I’ve got my headphones in, speed metal blaring in my ears, and I’m coding like a motherfucker. My fingers can’t keep up with my brain. I’m In The Zone. For most of my career, this image is what I’ve considered to be the zenith. When I come home and was in Programmer Man Mode most of the day, I feel like I’ve had a good day.
Pair Programming undeniably killed Programmer Man. This was a tough adjustment, since I’ve considered that mode to be my favorite for so long. I now see, however, that Programmer Man was, without me knowing it, Technical Debt Man.
When you’re coding like a motherfucker, you’re often writing bad code. You’re more likely to be outputting hundred-line methods. You’re sometimes willing to skip writing tests (tests slow down Programmer Man). You’re not pausing as much to think about design implications or ways that the code could be refactored. You may not have time to fix the code you’re working WITH; Programmer Man is too busy working on his own code to give a crap about some other guy’s code. Programmer Man’s code is almost certain to be more brittle and more poorly designed than if someone were sitting with him, making him slow down and THINK more often. Programmer Man’s code may not have been BAD, but it was generally worse than if he had a partner.
Programmer Man was too busy coding to do as much serious thinking, and the quality of the code suffered for it. And in the situations where you can be headphones-on, heads-down but still write tests and think about design, modularity, and quality, it’s almost certain that two heads would have been better than one. If you’re coding at a reasonable pace, pair programming will not slow you down. Conversely, if you code so quickly that pair programming slows you down a lot, you were making mistakes before. You need pairing more than anyone.
Programmer Man is dead, but I don’t miss him. Not anymore. My standards for what is “good code” have greatly increased and quite frankly I’m not sure ANY of Programmer Man’s code ever met that standard. Today, nearly all of my code does, and I have pairing to thank for it.
And the headphones situation is easy to solve as well – at work we pick a musical theme at the start of the day, then use Pandora to provide music consistent with that theme all day. I get my “Killswitch Engage” theme and my “Slayer” theme days because I graciously put up with another developer’s “Angels and Airwaves” theme and “The Cranberries” theme.
Final Thoughts
When I leave my job (which I don’t see happening any time soon) if the next company doesn’t do pair programming, it’s going to be a tough adjustment to me. It would be like walking into a new company and finding out that nobody uses version control – everyone just copies their changes to a shared directory at the end of the day. Sure you get the job done, but god damn you’re being inefficient about it. When people hiss at pairing because they can’t listen to headphones or don’t want to sit next to a fat guy, it sounds to my ears EXACTLY like someone complaining about SVN being too complicated.
I’m not going to advocate pairing, because anyone who reads this post and says “hey, maybe we’ll give it a shot” and then forces their team to do it will find that it doesn’t work. For pairing to work, everyone has to WANT to pair. That means they all at least need to be curious enough about it to give it a genuine shot – attempting pairing with the attitude of illustrating it doesn’t work will certainly show that it doesn’t work. If you’re holding onto Programmer Man, you’re doomed.
But if you’re willing to give it a genuine effort, push through the challenges and difficulties, read a book or two about how to pair, or maybe even hire a mentor to come to your company and help you pair for a few weeks, I think you’ll be pleasantly surprised by how effective it is.
Absolutely No Machete Juggling is a blog about software, programming, computers, and me. I'm a programmer working in Colorado, mostly with Java and Ruby. 
[...] I Love Pair-Programming: http://bit.ly/8OseSB When I first heard I’d be pairing at the new job, I was a bit apprehensive and skeptical. Do I really have to sit next to some fat developer all day, 40 hours a week? When am I going to check my RSS feeds? What if the other developer is gassy or hasn’t showered? How am I going to listen to my totally awesome Death Metal if I can’t wear headphones? Will the other developer be constantly judging and correcting my code? Will pairing prevent me from hitting “the zone” where I’m just belting code out so fast that my fingers can’t keep up with my brain? via nomachetejuggling.com [...]
Great article… you made me at least curious enough to give it a genuine shot…
Anyone who is interested in seeing what pairing is really like should check out http://pairwith.us. You can see a real pairing session, warts and all, with two really experienced developers. Those who are expressing reservations or opposition above: would really like to hear what you think after watching Antony and Andy for 25 mins (tweet me at @douglassquirrel)
Rod,
I really liked your story about Programmer Man. I think it reveals a hidden truth about the mindset for many of our peers…
Ryan
Dan:
I did change the reference. I wanted to reach for a simple analogy and used vi, which caused people to completely miss the point of the post and obsess over the vi thing instead. So I changed it.
Hey, did you take the vi reference out of the post?!
I’m reading all these incensed comments about vi and I started getting pissed off about it too .. then I realized that I hadn’t even seen it mentioned anywhere in the post!
Nonetheless .. thanks for a real world report about pairing, it’s one of those crazy alternative lifestyle choices I’ve always wondered about but was never really brave enough to experiment with (sort of like swinging).
And don’t diss vim. Ever, dude. Or the Programmer Man will take your lunch money.
[...] the ideal world of web (for more on why pair programming is so good for the web software folk, read this article by Rod Hilton). I felt particularly devastated by “the no-asshole rule” cause, [...]
[...] I can’t say anything new about paired programming in general that someone else hasn’t already said, but I can say this: it is freaking awesome. Others seem to agree. [...]
Being in the zone is not unique to software development… ( http://en.wikipedia.org/wiki/Flow_(psychology) )
And it does not take away your ability to choose – you can choose to write untested, unchecked, sloppy code in the zone, and you can choose to write good code in the zone as well.
“The Zone” is extremely valuable – and has some awesome side-effects that increase productivity and satisfaction. Your argument here makes pair programming less attractive – I like the idea of having someone checking my code – and there is a time to step out of the zone – but “Killing Programmer Man” is a depressing thought…I pity the place you’ve put yourself in.
Rod, you ignorant slut.
What are you trying to do restart the Great Editor Wars?
You obviously don’t know shit about vi, so why not stfu about it?
I enjoyed you little pair programming bit, but stick to what you know.
Well, a smelly programmer may be bad, but it´s still much better than smelly code!
[...] great story of someone who did try real pair programming I really recommend Rod Hilton’s post I Love Pair Programming. I’ll end with a quote from that post: I see pairing work so well every day that I consider [...]
[...] http://www.nomachetejuggling.com/2009/02/21/i-love-pair-programming/ [...]
Neither Killswitch Engage or Slayer is death metal, derp derp.
[...] source: I Love Pair-Programming [...]
I’m honestly envious. I killed off my “programmer man” years ago (not that I don’t like some honest to goodness breaks to thrash out with some good speed, death, or prog metal). But even though I stomped him well enough, I can’t seem to find a team willing and able to do real pairing like you describe. I’ve tried to get people into it, I’ve tried to bribe em’, but no go. It is so freaking hard sometimes to get people into something that is as scary sounding as pair programming. One day I do hope to either get a team put together that wants to do it or one of these years get on a team that does it.
Parag:
No, we don’t decide on pairs in the IPM. That’s a decision made daily/hourly.
We estimate the tasks as hours of time per pair. So if a task is “2 hours” the expectation is that 2 people will pair on it for two hours and complete it.
Great post. Thanks for sharing your experience.
I have one question. Does your team decide in the IPM, who will be pairing on which tasks. Also do you estimate tasks for the pair or on an individual basis, and then call decide your pair depending on who is available to pair on that day?
Great post. I’m an advocate of pair programming. I’ve worked with folks who refuse to do it and I’ve worked on agile teams that always do it. In my experience it takes people who want to write great code and who want to improve. It also takes a lot of humility to be willing to have someone call you out when you write something stupid.
I don’t think everything should be paired on, but it’s a great way to stay focused, talk through solutions, mentor/teach, and learn. It makes the entire team better then it was if everyone just worked by themselves.
The only thing I disagree on is the comment on vi. vi is a great tool. After learning to use vim, emacs, Eclipse, IntelliJ, and TextMate I have to say that the ones I dislike to open the most are the IDEs. My favorite choices are TextMate, vim, and emacs (in that order). I can’t remember the last time I needed to run Eclipse, but then again I stopped coding in Java a long time ago. ;)
Great post. You made me to think about some other stuffs in designing and programming fields. I would love to be a full time freelancer and I have to make a good plan for that.
Nice post with real examples of benefits. But I do want to put a point here. Let us compare with an example in a more real life. You need to reach a destination and set out single. While travelling you see a lot of stuff, think that there could be another shorter way, you experiment, sometimes succeed, sometimes fail, sometimes you destract etc.. and at last you reach the destination and then if you look back your foot trails will be very clumsy and cluttered to be followed and seem like you were not effective in reaching the destination. Now if you were accompanied in the journey i definetly bet the deviations would be very less, the experiments would be very less (or will be good experiments) and you reach the destination with cleaner foot steps to follow and you feel the journey is effective.
Its like putting the destination on priority than your way of travelling.
So you are getting disciplined in your approach(for the sake of effectively reaching the destination).
So pairing should help you realize the importance of the destination and advantage of being disciplined, but then again you should learn that and practice it on your own instead of having a pair all time. You always cannot afford another person for every journey especially if it costs.
So I recommend Pairing to realize the benefits and start putting it in your blood.
May be people who like to experiment (out of box) do not agree at all with this.
I think this article makes the same case against pair programming I usually do: if pair programming makes a big difference to your code quality, you were doing it wrong before. Pair programming helps exactly the people who wrote bad code when working alone. You can hire two of those people to write somewhat better code in pairs, or you could spend a little more and hire one good person to do it the right way from the start.
[...] I Love Pair-Programming – “I see pairing work so well every day that I consider my career prior to my current job to have consisted mostly of wasting time.” [...]
Dan,
So, first and foremost, I’m not an agile or XP coach by any stretch. Just a programmer that’s been doing pair programming and enjoying it a great deal. I’d be happy to offer advice, but if your company can afford it you may want to hire someone to come out and help your team.
1. Honestly, switch whenever. Sometimes we go the whole day without switching, sometimes two days in a row. We’ve developed something of an instinct about how much time can go by with someone not seeing work being done before we worry about “hit by a bus syndrome”. If it’s been two days since I’ve looked at the code a developer is working on, I know it’s been too long and I ask to switch stuff up. Do what feels natural, don’t force it unless it’s a problem.
One thing we tried was to set a timer for one hour. When the timer went off, the person who had been on a task the longest moved to another one, leaving another person to continue working on it. This worked somewhat well but it had disadvantages. You might give it a shot.
2. Research tasks don’t warrant pairs. Pairing is for writing production code. If you want someone to help, that’s fine, but pairing is really about improving the quality of the code that gets shipped.
[...] I Love Pair-Programming » Absolutely No Machete Juggling "I see pairing work so well every day that I consider my career prior to my current job to have consisted mostly of wasting time. When I think back to all the code I’ve written for a job, I’m annoyed at how much less efficient I was then since I wasn’t pairing, and how much better my code and my products would have been if I had paired on them full time." (tags: pair-programming efficiency risk-management software development cultural-norms TDD productivity) [...]