In pair programming, production code is written by programmers working in pairs. Each pair works on on one workstation and discuss and implement solutions together. Change pairs frequently to keep everyone up to date with the code. Some teams change pairs several times a day, while some switch pairs daily.
Pair programming helps spread knowledge of the code, tools, technology and domain around the team. It decreases feelings of individual code ownership (Collective Code Ownership).
On pattern for doing this is the driver – navigator pattern. The driver types is responsible for typing code , while the navigator is responsible for thinking about the solution – for example, what tasks come next, how what is being typed fits into the overall design, (if doing TDD) figuring out potential test cases and ensuring tests are written first, and so on. The driver and navigator switch roles frequently.
Another pattern shown with this is the ping-pong pattern. One person writes the test and hands over the keyboard for the other person to implement the solution. This ‘ping-pong-ing’ of the keyboard between the pair keeps both engaged.
Benefits of pair-programming
- Pair programming helps the developers keep focused and succumb less to distractions (like surfing the web). Pairing helps reinforce good habits like TDD and refactoring as the pair can help keep each other accountable to good software craftsmanship practices.
- Pair programming leads to fewer bugs and higher quality because 2 pairs of eyes are reviewing the code
- Working in pairs helps minimise gold plating code or needless refactoring. The navigator helps keep the pair on track based on the goal and the main tasks to accomplish.