Pair programming is the practice of pairing up to work on programming tasks. Usually, most people imagine two developers seated at the same computer, sharing the keyboard. But with the increasing popularity of remote coding platforms, it’s now possible to pair program thousands of miles apart.
Most forms of pair programming involve taking turns typing code or commands. One person types (the “driver”) while the other person thinks through what is being done, and what needs to be done next (the “navigator”). These roles are frequently swapped. Both members must verbalize their thought processes for pair programming to be effective. Successful pair programming relies on successful communication as much as programming skill. The premise of pair programming is that when working on a complex task, “two heads are better than one.”Find a senior developer to be your pair programming partner
The most important reason to pair program is that it often produces better solutions than either developer could have produced on their own. Problems are picked up on earlier and potential bugs are identified by two people instead of one. Before the pair settles on an approach to a particular problem, they discuss, evaluate, and talk through any trade-offs involved. Solutions are evaluated up-front rather than after they’ve already been implemented.
Pair programming provides a process for sharing knowledge and context that is built into your everyday workflow. For every line of code written while pair programming, two people have context on the code instead of one. This provides built-in redundancy if one person leaves, moves to a different team, is busy with other work, or goes on vacation. Without pair programming, developers must go to extra lengths to share knowledge, usually through extra meetings and code review sessions.
One of the biggest benefits of pair programming is learning from your partner. Pairing with a more senior developer is the best way for junior developers to improve their skills. Senior developers can also learn new things when pairing with a more junior developer, be it a nifty Linux command they didn’t know, how to use a new IDE, or how to be productive in the latest front-end framework. Everyone's an expert in something, and everyone has something to teach.
The requirements for pair programming are minimal: two developers and a shared command line or code editor. With these basic ingredients in place, there are many ways to approach pair programming, from the “Ping Pong Pattern” to much less structured forms. We’ll dive into different techniques for pair programming in the sections below, but they all have two critical things in common: turn-taking and open communication.
This form of pair programming is performed in conjunction with Test-Driven Development. One person writes a test and the other person makes the test pass. This pattern is effective because taking turns is built into the process. Make sure each member alternates between writing tests and passing tests. This can become a Ping Pong anti-pattern if the same person is always writing the tests (often the more junior or less confident developer) and the same person is always making them pass (often the more senior or more confident developer).
This form of pair programming is a looser form of the Ping Pong Pattern. It works a little bit like two people driving in a rally car race, with one person driving (or typing) and the other navigating. The driver carries out the navigator’s instructions, but has the opportunity to make corrections or ask for clarification. This style is an effective antidote for the anti-pattern where the person typing often controls what is typed, placing the other person in a passive mode where they are merely watching what is happening. The driver and navigator regularly switch roles every 15 minutes or so.
This is the kind of pairing that generally happens when no particular approach is being followed. It is free-flowing, with turn-taking between driver and navigator occuring as, and when, it makes sense. This freedom from structure can help naturally well-matched pairs move even faster. However, pairs that have different styles may struggle with the lack of structure involved here.
Pair programming is most effective when both people bring something unique to the table, whether that is knowledge, experience, or a diverse perspective. If you have the opportunity to choose your pair programming partner, it’s best to seek someone who can fill a gap in your knowledge or provide you with a different perspective.
Pair programming should never be done in silence. When a pair is silent, it might mean they are so perfectly in-sync that nothing needs to be said — this is rare. More often, it means that they are not sharing their thought processes. Whether you’re sitting with your partner or communicating remotely, good pair programming involves a lot of talking and thinking out loud. A good trick is to always narrate what you are doing and thinking whenever you type.
When one person types for a prolonged period of time, usually more than half an hour, this can be a symptom of poor pair programming. If the roles of driver and navigator are being properly shared, both members will take turns typing. If one person tends to dominate the keyboard, it may be helpful to set an alarm for 20 minute intervals to encourage role swapping. In pairs with a more senior person, the senior person must take particular care not to seize the keyboard whenever the junior person is struggling or going slowly.
Don’t be the person who insists your pair programming partner uses your hyper-customized Vim or Emacs with a thousand plugins unless they are as comfortable with Vim or Emacs as you are. By insisting on an environment that is unfamiliar to your partner, you’re doubling the cognitive load they must work through. If you are much more productive in the development environment than your partner, or vice versa, the balance of pair programming will be disrupted, and your partner will be less willing to “drive.” Use an IDE that you are both roughly equally comfortable with and use your highly customized environment as much as you like when you’re working alone.
Codementor is a online community of software developers with over 350K+ users and 10K+ vetted mentors. Our mentors make it their mission to help people just like you using tools like video calls, screen sharing, and shared code editors.
I am an experienced, committed software engineer who continually seeks clean, elegant solutions to business
Hi! My name is Ionică Bizău. If you're having problems pronouncing it, you can simply call me Johnny