What is pair programming?
Pair Programming is an agile development method where two programmers work together on one computer system to complete a programming objective. They collaborate and verbalize their ideas by communicating with each other directly in real time. The programmer writing the code is called the Driver, and the programmer who reviews the written code is the Navigator. Driver and Navigator usually swap roles after agreed intervals, which is usually several times during the work day.
Why use pair programming?
How can two people get one task done faster? Many development teams think that pair programming will be expensive because the cost of development increases. The idea is to use pair programming to reduce the cost of the steps after the program is written. There is significant evidence that pair programming reduces the number of errors in the code, the written code is easier to understand, problems are solved faster because two minds can solve a problem faster than one mind, and the entire team has improved cross-function training.
There are a several benefits of pair programming:
- Better communication between developers.
- Source code will have fewer errors as bugs can be discovered earlier in the development process.
- Programming solutions are more elegant because two people agreed on the written solution.
- Improved source code readability because of varied experience of programming pairs.
- Less wasted time when resolving critical issues.
- The team is more cross-functional and more than one person was involved in the source code development.
- Teams will feel more empowered to make decisions as a team.
- More expertise as development ideas and techniques are shared within the team.
- Team members deliver better quality as they get to know each other through daily communication.
- Team members rely less on management to provide day-to-day programming direction.
There are a few issues with pair programming:
- Pairing a novice developer with another novice developer can nullify any potential positive effects.
- Two developers working on simple tasks are a much less effective use of programmer time, and is a potential waste of effort and money.
- The two programmers must get along with each other or the development team will suffer.
- It can be difficult to track errors to a specific programmer, which can make training difficult to manage.
- The cost of doubling the programming expense, hoping to save money on the debugging and testing phases, might be difficult for management to approve.
Pair Programming Tips
- Switch Roles Often – Programmers should switch roles every half hour. They should stay in the Driver or Navigator role for no more than one hour to prevent mental exhaustion from being the Driver too long or losing the required level of vigilance in the Navigator role.
- Be Courteous – When pointing out errors or better ways of writing the code, be polite to avoid offending your partners ego. Finding errors and suggesting corrections are a normal part of programming, and should not be used as an opportunity for ridicule or punishment.
- Don’t Argue About Formatting – Matters of formatting and approved code structures should be resolved before the pair programming begins. Don’t waste valuable time arguing over how to indent code or when comments should be added.
- Novice Drives – The person who knows the least about the language or systems used should spend most of the time as Driver. This will keep the novice programmer engaged with less risk of the expert making all the decisions.
- Communicate – Pair programming only works if both people are talking. The Driver must talk about what they are about to type, why they are writing the program code a specific way, and why they think it is the best way. The Navigator must ask questions about what is happening, why it is written is this specific way, and they must be prepared to call out questions, errors, and potential issues without being prompted by the Driver.