Pair Programming

Marcos Araújo
December 15, 2020
<p>Pairing is a powerful approach to improve and reach greater results on a team/project. This post describes the <strong>Processes</strong> that Vinta’s team is following to pair program. To fully obtain the benefits of this approach, take some time to read the <strong>Introduction</strong> section to understand the styles, benefits, and common challenges you will encounter while pairing.</p><blockquote><strong>Disclaimer:</strong> Most of the content on this page is compiled from the “References”. The hard work was to understand their content, extract important pieces of information and organize them in a processual way.</blockquote><h2 id="introduction">Introduction</h2><p>Pair programming essentially means that two people write code together on one screen. It is a very collaborative way of working and involves a lot of communication. While a pair of developers work on a task together, they do not only write code, they also plan and discuss their work. They clarify ideas on the way, discuss approaches and come to better solutions.<br><br><strong>Pair programming styles:</strong></p><p><strong>Driver-Navigator</strong>: It consists of one person ‘driving’, taking the keyboard and coding or doing the work, while the other one is ‘navigating’. The Navigator’s job is to pay attention to the work being done by the driver while keeping the big picture in mind. They should guide the driver in the right direction. It is very important that driver explains verbally every decision they make, otherwise the navigator might lose interest and may stop paying attention. It’s healthy to switch roles every X minutes.</p><p><strong>Ping-Pong</strong>: This technique embraces Test-Driven Development (TDD) and is perfect when you have a clearly defined task that can be implemented in a test-driven way. A good strategy for this approach is to have one person writing the tests while the other one tries to pass them. As in the previous approach, you should be switching roles often.</p><p><strong>Strong-Style</strong>: This is a technique particularly useful for knowledge transfer, described in much more detail by Llewellyn Falco here. The rule: "For an idea to go from your head into the computer it MUST go through someone else's hands". In this style, the navigator is usually the person much more experienced with the setup or task at hand, while the driver is a novice (with the language, the tool, the codebase, ...). The experienced person mostly stays in the navigator role and guides the novice.</p><h3 id="benefits">Benefits</h3><p>Awareness of all its potential benefits is important to decide when to do it, how to do it well, and to motivate yourself to do it in challenging times. The main outcomes pairing provides are software quality and team flow..</p><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/vintasoftware-wagtail-ghost/blog/2020/10/image-20200801-230816.png" class="kg-image"></figure><blockquote>Team Flow: Is a state when a team optimize it’s time by moving into periods of high focus and productivity together. This type of flow is strongly related to the <a href="https://www.bbc.com/worklife/article/20190204-how-to-find-your-flow-state-to-be-peak-creative">state of flow</a>.</blockquote><p>Pairing requires different skills to get it right, and might even influence other processes in the team. For a team to be comfortable and successful at pair programming, they will have to work on skills that help overcome its challenges. Pairing gives everybody on the team a chance to work on these skills together.</p><h4 id="soft-skills-that-can-be-improved-during-a-pair-programming-session-">Soft-Skills that can be improved during a pair programming session:</h4><ul><li>Concentration and focus;</li><li>Task organization;</li><li>Time management;</li><li>Communication;</li><li>Giving and receiving feedback;</li><li>Empathy;</li><li>Vulnerability.</li></ul><h4 id="scientific-researches-">Scientific researches:</h4><p><a href="https://collaboration.csc.ncsu.edu/laurie/Papers/XPSardinia.PDF"><em>The Costs and Benefits of Pair Programming</em></a><br>Using interviews and controlled experiments, the authors investigated the costs and benefits of pair programming. They found that for a development-time cost of about 15%, pair programming improves design quality, reduces defects, reduces staffing risk, enhances technical skills, improves team communications and is considered more enjoyable at statistically significant levels.</p><p><a href="https://www.researchgate.net/publication/27295641_The_Case_for_Collaborative_Programming"><em>The Case for Collaborative Programming</em></a><br>A field experiment was conducted using experienced programmers who worked on a challenging problem important to their organization, in their own environments, and with their own equipment. Findings revealed that all the teams outperformed the individual programmers, enjoyed the problem-solving process more, and had greater confidence in their solutions […]. Teams completed their task 40% faster than the individuals.</p><h3 id="challenges">Challenges</h3><p>Pairing requires practice:</p><ul><li>While pair programming has a lot of benefits, it also requires practice and might not work smoothly from the start</li></ul><p>Pairing can be exhausting:</p><ul><li>When working alone, you can take breaks whenever you want, and your mind can drift off or shut down for a bit when it needs to. Pairing forces you to keep focus for potentially longer stretches of time, and find common ground with the other person's rhythm and ways of thinking. The increased focus is one of the benefits of pairing, but can also make it quite intense and exhausting.</li></ul><p>Intense collaboration can be hard:</p><ul><li>Working so closely with another person for long stretches of time is intense. You need to communicate constantly and it requires empathy and interpersonal skills.</li><li>You might have differences in techniques, knowledge, skills, extraversion, personalities, or approaches to problem-solving. Some combinations of those might not match well and give you a rocky start. In that case, you need to invest some time to improve collaboration, and make it a mutual learning experience instead of a struggle.</li></ul><p>Pairing with lots of unknowns:</p><ul><li>When you work on a large topic where both of you don't have an idea how to solve a problem, the usual pairing styles often don't work as well. Let's say you need to use a technology for the first time, or try out a new approach or pattern. Researching and experimenting together works in some constellations, but it can also be frustrating because we all have different approaches to figuring out how things work, and we read and learn at different paces.</li><li>When there are lots of unknowns, e.g. you’re working with a new technology, think about doing a spike to explore the topic and learn about the technology before you actually start working.</li></ul><p>No time for yourself:</p><ul><li>Being in a constant conversation with each other can be pretty energy draining. Most people also need some time on their own throughout the day. That is especially true for introverts.</li><li>Keep the pair programming to a maximum of 6 hours per day</li><li>When a pair feels that they don't have the collective knowledge to approach a problem, split up to read up and share back, then continue implementation.</li></ul><p>Pairing requires vulnerability:</p><ul><li>Vulnerability is often connected with weakness and in most modern cultures the display of strength is the norm. But as the researcher Brené Brown has laid out in several talks and books, vulnerability is actually a very important ingredient for innovation and change.</li></ul><h3 id="when-to-pair">When to pair</h3><ul><li>When dealing with complex tasks;</li><li>When dealing with boring tasks;</li><li>When you get stuck;</li><li>When onboarding a new team member;</li><li>When one person knows the subject matter well and the other doesn’t.</li></ul><h2 id="setup">Setup</h2><ul><li>Define who will be the host;</li><li>The host must track the sessions on Harvest;</li><li>If possible the host should turn on the mode “Do not disturb” on the computer to avoid distractions;</li><li>If you have an unusual keyboard/IDE setup check with your pair if they are okay with it. See if you can have a simple mechanism to switch your settings back to a more standard configuration for these situations;</li><li>Check with your pair if they have any particular preferences or needs (e.g. larger font size, higher contrast, ...).</li></ul><h3 id="local">Local</h3><ul><li>Use the host IDE or Text Editor, next time you pair with this person try to use yours, is good to switch to see how other softwares works;</li></ul><p>Default setup using a single computer:</p><ul><li>One mouse and keyboard;</li><li>Two monitors;</li><li>Sharing the same space;</li></ul><p>Elite setup using a single computer:</p><ul><li>Two mouses and keyboards;</li><li>Two mirrored monitors (or four);</li><li>Separated spaces;</li><li>Separated notebook to take notes and make research.</li></ul><h3 id="remote">Remote</h3><p>The host must use any video-conferencing tool with screen-sharing:</p><ul><li>Meets;</li><li>Discord;</li><li>Zoom;</li></ul><p>So that you both can switch the keyboards the host must use <strong>Visual Studio Code</strong> with <strong>Live Share</strong> plugin to share:</p><ul><li>Project Codebase;</li><li>Terminal;</li><li>Server (e.g. “8000”);</li><li>Try to use the webcam on, since people communicate a lot through gestures and facial expressions it is nice to see the shared screen and your pairing partner's video at the same time.</li></ul><h2 id="processes">Processes</h2><blockquote>1. Scheduling<br>2. Planning<br>3. Developing<br>4. Mini Retrospective<br>5. Celebrate achievements</blockquote><h3 id="1-scheduling">1. Scheduling</h3><ul><li>Define the task and goal of the pairing.</li><li>Create an event on google calendar inviting your pair.</li><li>Plan the pair programming to a minimum of 1 hour and a maximum of 4 hours per day.</li><li>Try to schedule the pairing on freer days, pair programming can be very energy demanding.</li></ul><h3 id="2-planning">2. Planning</h3><ul><li>Read through the story/card and play back to each other how you understand it.</li><li>Brainstorm and come up with a solution.</li><li>Choose the appropriate Pair Programming Style.</li><li>Plan your solution writing subtasks necessary to complete the full task.</li><li>Write the subtasks on the task.</li></ul><p><strong>When implementing a feature that requires you to use a technology you are both unfamiliar with:</strong></p><ul><li>Define a list of questions that you need to answer in order to come up with a suitable solution.</li><li>Split up, either divide the questions between you, or try to find answers for the same questions separately. Search the internet or other resources within your organisation to answer a question, or read up on a concept that is new to both of you.</li><li>Get back together after a previously agreed timebox and discuss and share what you have found.</li></ul><h3 id="3-developing">3. Developing</h3><ul><li>Develop one subtask at a time.</li><li>Use Harvest with a limit of 25 minutes to switch between roles.</li><li>After each session, you should take a 5-minutes break to drink water or go to the bathroom.</li><li>After 3 or 4 of these sessions, you must take a long break (15–30 minutes). It’s important to really take a break and tank energy, get some water or coffee, use the bathroom, get some fresh air. Avoid using these long breaks for other work, like writing emails.</li></ul><h4 id="styles-">Styles:</h4><p><strong>Driver-Navigator</strong></p><p>Driver:</p><ul><li>Takes the keyboard to write the solutions for the current subtask.</li><li>Should always talk through what is being done while doing so.</li><li>Should always ask for feedbacks when necessary.</li></ul><p>Navigator:</p><ul><li>Continuously revise and review what is being coded or typed.</li><li>Should always ask questions if doubts of what is being developed come up.</li><li>As navigator, avoid the "tactical" mode of thinking, leave the details of the coding to the driver - your job is to take a step back and add up to your pair's more tactical mode with medium-term thinking. Plan next steps, potential obstacles and ideas on sticky notes and discuss them after the tiny goal is done, so as not to interrupt the driver's flow.</li><li>Apply the "5-seconds rule": When the navigator sees the driver doing something "wrong" and wants to comment, wait at least 5 seconds before saying something - the driver might already have it in mind, then you are needlessly interrupting their flow.</li><li>As Navigator, don't immediately point out any error or upcoming obstacle: Wait a bit for the driver to correct or write a sticky note to remember later. If you intervene immediately, this can be disruptive to the driver's thinking process.</li></ul><p><strong>Ping-Pong</strong></p><p>Try to track which type of tasks better suit this approach</p><ul><li>"Ping": Developer A writes a test for the next bit of functionality you want to add.</li><li>"Pong": Developer B writes the functional code until the test passes.</li><li>Each "Pong" can also be followed by refactoring the code together, before you move on to the next failing test. This way you follow the "Red - Green - Refactor" approach: Write a failing test (red), make it pass with the minimum necessary means (green), and then refactor.</li><li>Developer B then starts the next "Ping", i.e. the next failing test.</li><li>Must develop one test at a time.</li><li>Each Developer must write only the test or the functional implementation.</li></ul><p><strong>Strong-Style</strong></p><p>Driver:</p><ul><li>Usually the driver is new with the setup, system, module or task at hand.</li><li>Reasons and challenges to the solution should be discussed after the implementation session, take notes to remember.</li></ul><p>Navigator</p><ul><li>Usually the more experienced person with the setup, system, module or task at hand.</li><li>Guides the driver on every decision.</li></ul><h3 id="4-mini-retrospective">4. Mini Retrospective</h3><ul><li>Reflect on how you both felt during the pairing session.</li></ul><p>Do a quick round of feedback for each other:</p><ul><li>Is there anything you would like to try next time?</li><li>Did you switch the keyboard often enough?</li><li>Did you achieve your goals?</li><li>Adjust this process.</li></ul><h3 id="5-celebrate-achievements">5. Celebrate achievements</h3><ul><li>Create your own way to celebrate achievements, like having good cup of coffee or eating something that you like.</li><li>Try to celebrate together.</li></ul><h2 id="conclusion">Conclusion</h2><p>Writing code together is not easy. It involves different skills and common challenges at the beginning. It is essential to keep the practice a habit so that the team can overcome its initial challenges and start getting all its benefits.</p><h2 id="references-">References:</h2><ul><li>On Pair Programming. <a href="https://martinfowler.com/articles/on-pair-programming.html">https://martinfowler.com/articles/on-pair-programming.html</a> 2020</li><li>Pair Programming is not a Panacea. <a href="https://www.mattgreer.org/articles/pair-programming-is-not-a-panacea/">https://www.mattgreer.org/articles/pair-programming-is-not-a-panacea/</a> <em>2014</em></li><li>Pairing. <a href="https://www.agilealliance.org/glossary/pairing/">https://www.agilealliance.org/glossary/pairing/</a></li><li>Pair Programming guide. <a href="https://tuple.app/pair-programming-guide/scientific-research-into-pair-programming">https://tuple.app/pair-programming-guide/scientific-research-into-pair-programming</a></li></ul>