Pair programming has been around since the early software development days. The agile software development technique has proven to be effective in improving code quality, developer productivity, and team camaraderie.
Yet, the topic of pair programming has had developers vouching for it and some against it.
Two developers pairing on a programming task (pair programming) is usually seen as a wasteful endeavor compared to solo programming. However, several teams argue that it boosts code quality with fewer bugs, development speed, shared learning, and developer productivity.
So, do the benefits of pair programming outweigh its costs? This post aims to share interesting insights on pair programming and how it can help development teams.
What Is Pair Programming?
In pair programming, two developers work together on a common task, where one writes the code (driver), and the other reviews and offers feedback (navigator). The same method is used when in remote pair programming work where developers are in different locations.
Driver – the person at the keyboard, focusing on the mechanics of the device used and entering the code
Navigator – the person who observes, thinks, and keeps an eye on the bigger picture. They also check for code accuracy.
Here’s a glance into their responsibilities:
In pair programming, the two developers constantly communicate with each other and often shift roles verbalize their thoughts, and tackle challenges as a team. This keeps them engaged and allows them to work collaboratively to accomplish the task they started.
There could be several pair programming styles:
Ping Pong: In this, the two programmers involved work in conjunction with Test-Driven Development. One developer writes the test and the other makes the test pass. Each member alternates between writing tests and passing tests. Since the two programmers are taking turns to build the code, this pattern is quite effective.
Driver-Navigator: This pair programming style works like two people driving a vehicle – with one developer driving (writing the code) while the other navigates. During the pair programming session, they can switch their roles every 15 minutes or so.
Unstructured Pairing: This method is different from other pair programming styles. In this type of pairing, no specific approach is followed. It’s a free-flowing approach where turn-taking between the driver and navigator happens as and when they feel comfortable. This pairing style lacks structure.
Benefits of Pair Programming
Improved Developer Efficiency
It is often thought that pairing two developers for a common task slows down the process or leads to errors.
The best example is probably of how NASA engineers saw productivity gains through pairing. The pair pressure effect led to intense productive discussions and code reviews.
It has been proven that pair programming helps achieve a predictable and sustainable development throughput – the number of features, tasks or chores, and bugs completed within a period that is ready to ship or ready to test.
Improved Code Quality
With pair programming, issues in code and potential bugs are spotted early. The pair programmers discuss, evaluate, and consider the tradeoffs before settling on an approach. The navigator is always on the lookout for errors while the driver is working on the task at hand. This hugely prevents bugs that otherwise get ignored for hours or days. Thus, partners in pair programming can spot bugs quickly, thus creating clean, functional, and optimized code.
Improved Collaboration
Pair programming allows developers to work on the same code base while sharing their knowledge and skills. This leads to improved problem-solving, enabling them to develop the best solution and avoid misunderstandings.
Thus, through pair programming, knowledge sharing and context building are built into the everyday workflow. Developers do not need to make extra effort for sharing knowledge or mentoring the new coder which otherwise is done through extra meetings and code reviews. The result:
- Shared experience across the team
- Quick learning for junior developers
- Improved team knowledge
- Better understanding of the task
- Improved developer confidence and happiness
Collective Code Ownership
Since both developers are involved in the same programming task, they have equal rights and responsibilities over the code. Pair programming upholds collective code ownership that:
- Gives them the freedom to make changes to the codebase because they don’t need approval from anyone.
- Tackles the ‘not-my-problem’ syndrome that is common with traditional programming practices. Improves code quality as each developer strives to keep their part of the code clean and well-designed.
- Makes developers feel more invested in the project because they have a stake in it – the code they have entered and helped in building as a navigator.
Cons of Pair Programming
Conflictual Moments
What happens if the navigator doesn’t like the code written by the driver? What if the driver doesn’t agree with the navigator’s suggestions or analysis? Issues have multiple solutions. If the pair doesn’t agree on one, there could be a conflict, resulting in them splitting.
Complexities
It is generally believed that tasks done by a single person are simpler than assigning them to two people. The situation gets further complicated when the partners are varying skill levels. More often than not, the skill gap can lead to issues in the workflow, complicating matters.
Farhan Thawar (VP of Engineering at Shopify) Shares His Experience with Pair Programming
Farhan is the VP of Engineering at Shopify. He’s been a strong advocate for pair programming and shares insights on why pair programming makes complete sense for developers.
Here are the pair programming use cases he shared in an interview with Supermanagers Podcast.
The first project he and his team worked on was Shopify Capital. The developers using Spark and Python leveraged pair programming to build ETL tools (extract, transform, and load) and manage frauds in eCommerce.
Farhan has paired with several developers of different skill sets and experience. He believes pairing is a high-fidelity method to work on programming tasks and engage in the problem-solving process. It improves code quality, reduces defects, and increases productivity. Though many believe that pair programming slows down development, he shares that its benefits far outweigh its drawbacks.
Practical Recommendations to Make Pair Programming Work
Here are a few best practices we recommend to make pair programming work for your development team.
Position it as an Investment in Quality and Learning
If you need to convince your team of the benefits of pair programming, focus on its role in improving quality and developer learning. Good developers are hard to come by. Hence, pairing a beginner with an intermediate or expert developer can boost learning and skills for the entire team.
Encourage Pairing for Complex Tasks
Pair programming is most advantageous for complex projects where junior developers struggle due to lack of experience. In such cases, experienced developers can use their judgment and experience to help beginners write good code on their own. A daily Scrum can help teams determine complex projects and pair the most suitable developers for the task.
Avoid Huge Experience Gap
Though it is ideal to pair developers with varying skill sets, make sure the experience gap isn’t too large. For the junior developer, the learning curve would be enormous in terms of writing and reviewing the code, product insights, and other technical aspects. However, working with a slower partner could be frustrating for the senior developer. Another angle to this is having developers with violently different views on developing software. This can make it tough for them to agree on a solution, thus delaying the project delivery.
Focus on the Prevention of Code Smells and Errors
Though code smells produce an output they aren’t good for your code. They slow down the processing, increase the risk of errors, and make the application vulnerable to bugs. Thus, smelly code leads to poor code quality and increases technical debt.
Since code smells like Blob Class, Complex Class, Spaghetti Code, and others take time to change and are tough to understand, pair programming works best to manage them.
Weekly tech talks between developers can help them explore these and agree on a shared definition. They can also agree on whether or how much of a priority it is to prevent a particular smell.
During pair programming developers critically review each other’s code, thus helping them recognize the smells early and avoid them in future work.
Measure the Value Pair Programmers Bring to the Table
It is critical to measure the effectiveness of pair programming. Here are a few areas that can help:
Development time – How much time is being spent on development resources – paired versus solo programming?
Developer satisfaction – This can be measured using employee satisfaction metrics like employee net promoter score, employee turnover rate, absenteeism rate, and others.This can be easily achieved through employee satisfaction surveys and engagement metric trackers like Zavvy, CultureMonkey, and Sogolytics. Time to resolution – How many bugs have the team spotted and resolved? How much time did it take?
Even with pair programming in action, you cannot completely avoid JavaScript and HTML errors from surfacing on your eCommerce website. Therefore, you need an automated mechanism to proactively detect these errors and flag them to your development team in real-time.
Noibu is an eCommerce error monitoring platform that detects all website errors and alerts your team in real-time, while also providing actionable solutions for resolving them efficiently without having to replicate them. It helps boost your development team’s productivity by reducing the time to resolution as they no longer need to spend hours trying to find the root cause of errors. Noibu does all that for you and provides you with the exact line of code that needs fixing in order to resolve the issue.
Take Home
If you look at past research, a lot of it points to how pair programming takes slightly more developer hours than solo programming. However, the investment is worth it when you consider the quality, learning, and enjoyment it brings along. All these eventually boost developer productivity.
Hence, as we conclude, we would like to stress two points –
- Be open to adopting pair programming to improve your developer productivity and code quality. Test it on a small scale and constantly ask your team about their opinion.
- Measure your pair programming efforts to see if they add value. This will help you to improve development time, bugs/errors spotting and fixing time, user experience, and overall developer satisfaction.
Follow Noibu’s blog for detailed information on such topics.