Why Pair Programming Makes a Difference and When You Should Do It
Tags: code, programming, career, beginners
Published: 2023-05-23 09:25:31

---
title: Why Pair Programming Makes a Difference and When You Should Do It
published: true
date: 2023-05-18 10:18:11 UTC
tags: code,programming,career,beginners
canonical_url: https://x-team.com/blog/pair-programming-why-and-when/
---
Pair programming is a programming technique where two software engineers collaborate on a piece of software simultaneously. In an office, this is done at a single workstation where the two engineers sit side by side. Remotely, this is done through a communications channel like Zoom, Hangouts, or Teams, and a collaborative IDE like the [Live Share](https://visualstudio.microsoft.com/services/live-share/) extension for Visual Studio.

The two engineers each take on a role when pair programming. One engineer is the _driver_ who writes the code and makes tactical decisions. The other is the _navigator_, who reviews the code on the go, gives directions, and stays focused on more strategic decisions. Unless one engineer is much more experienced than the other, both engineers should frequently switch roles to stay engaged and share the different workloads equally.

## The Benefits of Pair Programming

Pair programming is a controversial topic because it doesn't work in every scenario. It's not something you can simply start doing without considering how to do it. It's a skill that takes some effort to get good at. But the benefits of pair programming are genuine.

First, it **improves the quality of your software**. A [meta-analysis](https://www.sciencedirect.com/science/article/abs/pii/S0950584909000123) found that pair programming leads to higher-quality software when compared with solo programming. This makes intuitive sense, because you have two sets of eyes looking at the same code at the same time.

Second, pair programming **speeds up knowledge transfer** between engineers. There will always be differences between how you program and how someone else programs, even for the simplest of applications. You'll always learn something new by watching someone else program and being able to ask questions about why they did something a particular way.

Third, when done correctly, pair programming ensures that engineers are **intimately up-to-date with the entire codebase**. No engineer works on a piece of code entirely on their own. Instead, they work together with other engineers and, in the _navigator_ role, have to consider how any particular feature fits within the larger codebase.

Fourth, pair programming helps to **quickly onboard new team members**. When a new engineer joins a company, it can take a while before they're familiar with the codebase. Not only does pair programming speed up this process, but the engineers will be able to hit the ground running with the help of someone who's already familiar with the codebase.

## When Does Pair Programming Not Work?

Let's start with when you _shouldn't_ do pair programming:

- When you need to be [in the zone](https://x-team.com/blog/flow-state-of-mind/). Sometimes you just need to crank out some fresh code and you're better off doing it on your own versus collaboratively.
- For routine or simple tasks. Pair programming is quite intense and may not be worth the mental effort for tasks that you can easily do on your own.
- When you have extremely tight deadlines. Although pair programming often results in better-quality code, it can take a little longer to get there.
- When the engineers aren't compatible. Not all engineers work equally well together. Always ensure there is a reasonable match between the skill levels, experience, and work styles of both engineers.

## When Does Pair Programming Work Best?

Pair programming is the most effective in the following scenarios:

- For complex problems that require brainstorming. Two engineers can come up with more and better solutions than one engineer. Scenarios include algorithms that touch many parts of a codebase or have intricate business logic.
- For fast test-driven development (TDD). There's a pair-programming scenario called _ping-pong_ where one engineer writes code along with a failing test for that code. The other engineer then takes over and rewrites the code until it passes the test, then writes a new failing test for the updated code.
- When writing high-stakes code. Especially for code related to security or performance or a business-critical feature, it's better to have two engineers working on the problem over one. Their combined knowledge will drastically decrease the chances that something goes wrong.

## In Conclusion

Pair programming isn't necessarily a must-do. But as long as the two engineers communicate properly, set good objectives for every session, and take frequent breaks, it can be a great tool in an organization's toolbox to improve the quality of its code.