Intro to Pair Programming

Hawaa Zaroual
5 min readSep 19, 2021

--

What is pair programming?

When it comes to solving problems as a programmer sometimes it pays to work with a second person as two minds can be stronger than one. Pair programming is a collaborative team effort where the pair will work on one machine only taking turns writing code. One programmer takes on the role of the driver and the second programmer takes on the role of the navigator. The programmers can switch roles at any times!

Pair Programming

Defining the roles

I mentioned that each person can either be a driver or a navigator. A driver is the person who does the typing. An example is writing out functions, creating objects, writing out the logic. The navigator will be speaking out loud, voicing the logic that should be implemented by the driver. The navigator also looks out for any errors the driver may have made when writing out the code. Below is an example of an interaction between a driver and navigator.

Pair Programming Demo:

Navigator : ‘I think first we need to import the Fun function from the helpers file.’
Driver: *writes at the top of the file an import statement*
Navigator: ‘Now, we want to use the Fun function inside of a new function that we can call makeFun, and I think we also want to make a new variable with an empty array to push the results.’
Driver: * declares the makeFun function, and makes the new variable*, ‘Which scope should the empty array be in?’
Navigator: ‘I think it should be inside the makeFun function not outside of it.’

Working remotely or in person

You can pair program in person or remotely which makes this method of programming to be flexible. When in person the pair can use one machine, one mouse, and one screen (or two so no hovering happens). This ensures that only the driver is directly writing code while the navigator sits by their side and talks out the process. On the flipside, when in person pairing is not possible programmers can still pair program remotely. This can be done by live code sharing. I like to use Visual Studio Live Share as it allows both programmers access to the folder/file being worked on. In order to get the full experience of pair programming the pair can also use Discord, Slack, or Google Meets to set up a call which allows for smooth communication between the pair.

Cautions on how to properly Pair Program

It may be tempting as the driver or navigator to take control and write out the code as you want it. However, you must resist the urge. As the navigator you may feel frustrated and want to start typing the code. On the other hand, as the driver you may disagree with the navigators direction which tempts you to write out the code how you think it should be. While feeling frustrated at times is totally valid, remember to respect your role and your partner. This is where taking breaks or switching roles can be helpful. You want to avoid taking full control when pair programming because it defeats the purpose of pair programming.

Advantages of Pair Programming

An obvious advantage of pair programming is that you don’t have to solve a problem on your own which can take longer than if you pair up with someone else to work through it with you. Some benefits are:

  • Improve your learning. Pair programming is a wonderful way to learn from your peers. Both partners bring their own set of skills to their session which allows for the transfer of knowledge between partners.
  • Write cleaner code. With two set of eyes on the same code, errors and bugs can be caught sooner rather than later. The programmers can also suggest different ways to write the code which can lead to a cleaner look in general.
  • Work on teamwork skills. Programming together pushes the programmers to practice communication, explaining their logic, and listening skills as well.
  • Get live feedback as you code. If the driver writes code one way the navigator may suggest a neater or more efficient way to write the code.
  • Practice being a driver and navigator. Switching roles ensure both programmers get practice writing out code and communicating the direction the code should take.

Disadvantages of Pair Programming

The advantages of pair programming assumes that you are compatible with your partner and have enough experience pair programming to have a smooth coding session. Unfortunately, this is not always the case. Some cons are:

  • You’re not learning. What I mean by this is that your partners skills may be a bit more advanced than yours and they take full control at times. This means that you are not fully understanding the thought behind the code they are writing. If this starts to happen try to switch roles or communicate that they are overstepping their role.
  • The interaction is quiet. It may be hard for both programmers to talk out loud during the process. However, it is important that both partners practice vocalizing their thoughts as this will help speed up the process and both programmers will be on the same page.
  • Personality clashes. This can be tough to navigate. When personalities are compatible, pair programming can be a smooth process and even fun. It can be hard to have a successful session if you and your partner are simply not getting along. If this is the case then the pair should take a break and consider getting different partners.
  • Different speeds. This can happen if the navigator is going to fast or the driver is moving a few steps ahead of the navigator. It is important to check in with your partner to make sure that you both understand what is happening. If your partner is not following along then it is important to slow down and explain the thought process behind the actions. Another way to address this is to pause and discuss the direction you want to go in. By doing that you are bringing each other up to speed.

Successful Pair Programming

If you’re wondering what successful pair programming is then lucky for you because I will tell you. The main indicators that a pair programming session is successful are that you:

  • Practiced being a driver and a navigator
  • You learned something new (even if it’s a small shortcut)
  • Both partners contributed equally
  • Each partner asked questions or clarifications at least two times during the session
  • You solved the problem and in a timely manner

Now that you know what should generally be accomplished during a pair programming session let me outline some steps that can help you achieve a successful session:

  • Discuss the goal
  • Set a general time interval for when you switch roles
  • Ensure you take breaks from actual coding
  • Review the code together, review it, and refactor if needed

Power to the Pair Programmers!

Teamwork!

Now that you know what pair programming is, why programmers do it, and why it’s so great; now you too can be a powerful pair programmer. Don’t be afraid of pair programming because ultimately you will become a better programmer when you work collaboratively in this way.

Author: Hawaa Zaroual

References

What is Pair Programming? Advantages, Challenges, Tutorials & More

Pair Programming

Pair Programming Explained

--

--

Hawaa Zaroual

I am a new Full Stack Developer that seeks to share my experiences blog style.