Two Heads Are Better Than One: The Hows & Whys of Pair Programming

If you’ve been in tech for any amount of time, you may have heard the term “pair programming”. What is pair programming, and why do developers do it?  Pair programming (also referred to as “pairing”) happens when two programmers work together on the same problem, often at the same computer–with one actively writing code (“driving”) and the other reviewing the code and suggesting ideas and improvements (“navigating”).  Pairing can also be done virtually over a remote meeting platform, with one developer driving and another reviewing the code over a shared screen.  Think of it as the programming-themed embodiment of the saying, “two heads are better than one”. 

Pair programming has a number of benefits: it can improve the quality of code on a project, reduce the risk of introducing bugs and other flaws in the software, improve communication between developers, and lead to faster problem-solving.  Here’s how: 

Improvements in Code Quality:

Having two sets of eyes on the code helps mitigate the risk of making mistakes and introducing bugs in the software.  The role of the navigator is to monitor for quality as the code is being written and suggest fixes and improvements, which often leads to higher quality code on the first attempt at problem-solving.  It’s a little like having a code review while still in the process of writing the code, which means that issues are caught as they occur, instead of after all the code for a solution is written. 

Improvements in Software Design: 

Collaboration between developers can lead to better design decisions and higher quality software.  While pairing, the navigator can offer an alternative perspective on whatever problem the driver is working on, so pair programming often encourages discussions about the best way to arrive at a solution.   Because of the availability of real-time feedback, pairing can reduce the risk of introducing design flaws, which can also prevent the need to re-architect a solution later on.

Improvements in Developer Communication: 

Pair programming requires practicing communication skills by its very nature, and it can help enable team members to build strong working relationships.  Developers also tend to be more accountable when working in pairs, because working together means staying focused on the task at hand–active pair partners are less likely to procrastinate on work or make careless mistakes.  Pairing also encourages teammates to make decisions together, compromise if necessary, and effectively communicate their thoughts, ideas, and questions while developing a solution. 

Improvements in Solution Speed: 

Complex problems can often be solved more quickly by two people working together instead of one person working alone.  If one of the pair gets stuck while working on a problem, the other can suggest potential solutions or work-arounds.  Additionally, developers can potentially learn new problem-solving techniques by observing how their pair partner approaches different challenges.  Being exposed to different work styles and ways of thinking about programming helps to broaden perspectives and can encourage different ways of thinking about solutions and problem-solving.

Conclusion

These aren’t the only benefits of pair programming–there are many more, particularly for junior developers, but that’s a topic for a different article!  It’s important to note that pairing may not be suitable for every task, and that there are programmers out there who are not fans of pair programming–some folks just prefer to work independently, and not all problems require intensive collaboration.  However, when you have a complex task that may require more than one big brain, the benefits of pair programming are pretty clear: it can speed up problem-solving, result in higher-quality code, and help encourage teamwork.  Happy pairing!

Add a Comment