Pair programming is working together with someone else to code a solution to a problem. It is a common industry practice and can be used effectively by engineers spanning all skill levels, not just as a learning tool but as a means of writing high quality, professional code.
As a CYF trainee you might find it useful when working in pairs on a project with another trainee, or trying to get past a blocker.
The Driver and The Navigator
In a pair programming scenario, one person is the driver and the other is the navigator. Understanding the responsibilities of these roles and how to fulfil them is key to learning how to pair program productively.
The Navigator
The navigator is responsible for outlining the approach to solving the current problem. It’s their job to provide high-level instructions to the driver about what to implement and to review the code that is written.
Tips for being a good navigator:
- Focus on the broader guidlines and avoid specifics, i.e. you should favour “we should loop through this array” rather than “you should write ‘for’ and then an opening bracket, then the
letkeyword…”, unless the driver has asked for specifics - Listen and respond to questions or requests for clarification from the driver
- Don’t dominate; whilst it’s your responsibility to guide the solution, you should still be open and receptive to suggestions from the driver
- Resist temptation to write code, including avoiding sending code to the driver to be copied into the codebase
The Driver
The driver is the one who is writing the code. They have their hands on the keyboard and are responsible for implementing the high-level instructions given to them by the navigator.
Tips for being a good driver:
- Be willing to implement the navigator’s suggestions, even if it might be different from how you would approach the solution
- Feel free to offer suggestions and ideas, but respect that the navigator will make the final decision about approach in that moment
- Don’t be afraid to ask questions and engage the navigator in a discussion, especially when their instructions aren’t fully clear to you
Swapping Roles
You should swap roles regularly. A good baseline to start from is:
- Swap roles every 25 minutes
- Each time you swap, take a 5 minute break
Why
There are lots of benefits to pair programming, including:
- Live code review - there’s always another programmer present to check the quality and robustness of the code being written
- Faster debugging - a second person looking through the code can help speed up the process of catching bugs
- Filling knowledge gaps - you can navigate your pair through a topic they’re less familiar with, and vice versa
- Learning - regular opportunities to learn from someone with different expertise
- Developing communication skills - by definition, you’re having to explain your approach clearly and succintly to someone else
Can you think of any more?
How
You can do pair programming in person by sharing one computer.
You can also do it remotely:
- By sharing your screen using a slack huddle
- Scheduling a Google Meet, or similar online meeting
- Using a VS Code extension like CodeTogether or Live Share.
Extra Links
You may find these links helpful if you want to learn more about the Driver/Navigator style: