Pair programming can be a very valuable tool but it is almost always uncomfortable at first. A good portion of that discomfort is because pair programming pushes you to interact and learn from each other in ways that are very effective, but also require a certain amount of vulnerability. This isn’t bad. Pretty much anything that really pushes you to be your best is going to take you outside (or at least to the edge) of your comfort zone.
This post covers some basics for teams who are starting pair programming. It is by no means exhaustive but should provide a good foundation for teams looking to avoid common pitfalls.
Mechanics of Pair Programming
Ideally, pair programming is an activity with two people sitting side by side sharing a computer and talking through the process as they create software. The ability to physically point at the screen and pass the keyboard back and forth minimizes the communication overhead with this type of programming.
The pair should pass the responsibility for driving back and forth. Sometimes it makes sense for the person who isn’t driving to have a computer in front of them. For example, they could use it to lookup the details of an API or some special syntax as it is needed. They should not be sitting there browsing Facebook and checking their email. That defeats the entire purpose of working together.
Remote Pair Programming
Sitting side by side and sharing a computer is ideal, but many teams are distributed, and you may want to pair with someone who isn’t physically in your building. Pair programming using a screen share tool can work. However, it is much more difficult to hand control back and forth. One way around this is to develop in a branch where you can easily push and pull your changes. That way both members of the pair can stay up-to-date on the code and switch back and forth between who is driving.
While many teams do pair programming with voice and screen share, video conferencing software is preferable to just talking on the phone. It is beneficial to see each other, observe body language, etc. Of course, video conferencing isn’t particularly useful if your screen is filled with the code. You’ll need a separate monitor or television screen for the video to make this work well.
There are newer tools that allow for pair programming inside the IDE. For example, Visual Studio Code and Atom are both introducing the capability for two people to work simultaneously on the same code. If you’ve ever used a Google Docs with multiple people at the same time, you will have a pretty good idea of how this looks. You can see each other’s changes in real time.
Regardless of what tool you use, make sure it is fast enough. Trying to pair program with a two-second delay is very painful. If you build your opinion of pair programming on experiences where you are trying to talk in real time while looking at a screen that is two seconds behind your pair, you are likely to conclude that it isn’t worth the effort.
Shared Ownership Of Code
One of the big goals of pair programming is to make sure that the entire team owns the entire code base. There may be sections of the code that different people are more familiar with, but proper pair programming should help make sure that knowledge about every part of the code gets disseminated throughout the team.
We Instead Of You And I
Pair programming is an activity that requires vulnerability. This is easy to remember when you are the one driving and easy to forget when you are not. Even simple things like using the word “we” instead of “you” to point out problems can go a long ways toward making the interactions less threatening. “We” also helps foster a sense of teamwork, a shared responsibility that is vital to work together effectively.
Think Out Loud
Pair programmers are working together as a team. This means you need to talk through what you are thinking as you do it. You can’t just go silent and tear through writing code, hoping that your pair can keep up. It should be a conversation with suggestions and ideas coming from both of you. Thinking out loud means you may say some things that seem rudimentary, but that is fine. You are working together to solve programming problems. The best way to do that is for both of you to know what each other is thinking as you work through it.
Shared Understanding
Both members of the pair should understand what the code is doing. If your pair is questioning whether something is correct, take the time to make sure you both agree it is right. Even if you know it is right; you can’t steamroll over them. Together you will be more effective if you both fully understand why everything works.
This may mean taking a slight detour to explain something your pair may not be familiar with. This is how you work together as a team. You are making an investment in shared understanding that will have returns well beyond your current coding session.
Spreading Knowledge
One of the benefits of pair programming is the way it spreads knowledge throughout the team. Every programmer has a few shortcuts and tricks that make them more effective. Programming together lets both members of the pair learn from each other.
When two people program together, it is very common for them both to learn each other’s favorite keyboard shortcuts and command line tricks. This may sound trivial, but it is amazing how fast these small but meaningful efficiency gains can spread through a team.
I have seen instances where a junior and senior programmer were pairing together. The junior programmer was able to learn a lot of very important lessons about structuring code from the senior member, but it worked both ways. The junior programmer was more familiar with some of the newer features of Java and was able to show the senior programmer how to make some significant improvements to the code.
Alternate Pairs
You can further spread knowledge within the team by switching up pairs on a regular basis. Ideally, you want everyone to have a chance to program with every other team member. Switching up the pairs for each story can be a good strategy.
In effective teams, this tends to happen naturally. If Bob is the expert on Spring Batch and a new story is coming up that will require Spring Batch expertise, Alice may ask if she can work on the story with Bob so she can learn more about it. Teams that have worked like this for even a few months see significant efficiency gains as new expertise and best practices make its way rapidly from team member to team member.
Is Pair Programming Efficient?
When I mention pair programming to management, their first concerned is that a team of eight people working in pairs will only output half as much code. This makes sense if programming is mostly about typing, but it isn’t. Most of the effort in programming is spent thinking. One of the best ways to solve thinking problems is to talk through it with someone else. This is exactly what pair programming does. The time spent typing is insignificant.
That isn’t to say you can’t be inefficient in pair programming. I’ve heard horror stories of developers pairing with someone who simply played with their phone whenever they weren’t at the keyboard. On the other hand, when the developers are both engaged, it is usually a very satisfying and efficient way to work. Often developers comment that it is significantly more intense than programming alone because working with someone else keeps the work focused and moving along.
Take Breaks
When two people are intensely working together it can be easy to skip breaks. Don’t do this. Don’t skip lunch because you think you’ve almost solved a tricky problem together. Getting away from the work for a few minutes gives your brain a chance to solve problems in the subconscious.
Both members of the pair should take breaks at the same time. If both members are comfortable saying, “I think we should take a break now” then they can be done on an ad-hoc basis. With people new to pair programming, it can be better to decide when you are going to take a break up front. Breaks are essential for making progress and if there is a chance that neither person will be comfortable suggesting a break, then determine when you are going to break before you begin programming.
Hygiene
Be aware of the fact that you are going to be working in close proximity to someone and be considerate. You may want to save garlic for days when you aren’t going to be pair programming. Heavy perfume or cologne that smells great to you may give your pair a headache so be thoughtful.
I once did a phone and screen share interview with a developer who was physically at my client’s office. The guy seemed to know his stuff, but after the interview, my clients who were in the office with him didn’t seem very impressed. They weren’t exactly forthcoming because no one wanted to just come out and say that they weren’t comfortable working next to this guy. I don’t know exactly what the issue was, but they threw the keyboard away after he was done using it for the interview.