Pair Programming Strategies

People might think that coding is a thing you do alone, but that couldn't be further from the truth. If you're not familiar, Pair Programming is a an concept where two people sit at the computer and take turns writing code. Before coming to 8th Light as an apprentice, I mainly only worked on projects alone. Being the only developer on a project limits your continued learning in many ways, especially as a new developer. However, now that I have had the opportunity to work with other apprentices and more experienced Craftsmen on projects, I have learned the benefits of Pair Programming.

There are two main methods of execution in Pair Programming. Each are a little different, but they give each person a specific role in a session.

1. Ping-Pong

Ping pong pairing is when each pair takes turns writing code. This can be accomplished in a couple ways, one is where one pair only writes the tests, while the other only makes those tests pass. This way I personally don't like only because I think it's good for each pair to have the chance to write both the tests and the code itself.

Another way, which addressses this issue, is when one pair writes the tests, and then the other pair would write the code to make that test pass. Then the one who made the test pass would then write another test, and the cycle would repeat. I have found that this style of pairing gives each person ample opportunity to practice writing tests and getting them to pass.

2. Driver-Navigator

The Driver-Navigator style of pair programming is where one person is a "driver" and the other, a "navigator". The driver's role is to be typing the code, while the navigator sits and gives feedback and provide direction for the design when appropriate. There are a few times when I believe this style could be really helpful. One would be when I'm pairing with mentors, who might not be completely familiar with the code. The mentor could be providing direction and feedback on the code, while I would be writing the code.

However, this style could potententially have some shortcomings. This style can be tiresome for both pairs if only one person is writing the code. The driver could get tired from writing code for a long period of time, and the navigator could get bored from sitting there watching intently. The navigator could be tempted to go and get distracted and go check their e-mail, their phone, or do something unrelated to the code.

Which style should you use? #

I wouldn't say that one is necessarily better than another, or that one style should be used over another. Simply because I believe it largely depends on the experience of the pairs. If both developers are pretty experienced, it would probably seem reasonable to go with the ping-pong method. The Driver-Navigator method might be better for two pairs of varying experiences. So far my experience with pairing has been a bit of a combination of both styles. Usually when I was working with somebody using the ping-pong method, the person who wasn't taking control of the keyboard would have to act as a navigator.

Throughout my apprenticeship, each time I had the chance to pair with somebody, I have always come out of the session learning something new even if the session is short. Sometimes it's a new shortcut for your editor, a cool tool to make life easier, or new ways to approach problems. Pairing has been a great opportunity to learn new things quickly. Not everybody thinks in the same way, so having an extra set of eyes on your code as you type will help come up with a better solution.

🙏🙏🙏

Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖! For feedback, please ping me on Twitter.

Published