Skip to main content

Pair Programming

"Given enough eyes, all bugs are shallow." - Linus's Law, Eric Steven Raymond

Peer review is known to be a good development practice that enhances software quality and team collaboration. Since it is productive, why not program and review in pairs all the time?

In XP, all production code is created through pair programming. This means having two people working together, like a pilot and co-pilot, on a single computer, focusing on one task at a time.

What XP indicates is to program in pairs when writing production code. It’s not necessary to program in pairs 100% of the time, as activities like research and reading do not require or benefit from this practice.

Key Points

  • Intense Collaboration: Pair programming promotes intense collaboration between team members. The two developers work together on the same computer, sharing ideas, knowledge, and responsibility for the task at hand.

  • Roles of "Driver" and "Navigator": In pair programming, one developer acts as the "driver," who controls the keyboard and writes the code, while the other acts as the "navigator," who reviews the code, offers insights, asks questions, and suggests improvements. The roles can be alternated during the session.

  • Real-Time Code Review: Code review happens in real-time as the code is written. This helps to identify issues and errors earlier, resulting in higher-quality code.

  • Knowledge Transfer: Pair programming is an effective way to transfer knowledge between team members. More experienced developers can collaborate with less experienced colleagues, helping to enhance the overall skills of the team.

  • Continuous Feedback: Developers provide each other with feedback in real-time, which helps in finding more efficient solutions and better programming practices.

  • Error Reduction: With the constant attention of two developers, pair programming helps to identify and fix errors more quickly, thus reducing rework.

  • Joint Decision-Making: Pair programming promotes joint decision-making regarding the design and implementation of code, ensuring that both perspectives are considered.

  • Focus on Task: Pair programming encourages focus on the task at hand, minimizing distractions and interruptions.

General Concerns

"Two programmers doing the work of one? That doesn’t make sense."

Statements like these are often made by those who are unfamiliar with the productivity and benefits of pair programming, or who still think in terms of traditional manufacturing processes with one worker per station.

Software development is a complex activity and should not be treated like a manufacturing process. The XP coach should be attentive to the organization of the environment, manage the change with a managerial vision, and harmonize human relationships. Two people working on a single computer will produce more than two people working separately, as it increases focus, quality, and knowledge sharing. Over time, the advantages and benefits will become clear; just believe in the team's potential. Those who practice pair programming experience its benefits firsthand.

Teamwork

  • "Your Idea First"
  • Thinking Something Through
  • Ten-Second Rule
  • Time Cycles and Rotation
  • TDD Cycle