We first learned about paired programming at a Software Cornwall event when Kat took part in a mob programming workshop. It's a technique for writing code that involves two (in the case of paired) or more (in the case of mob) people. It's commonly used within the Agile development framework but it's a useful practice in any context.

What's the quickest and most efficient way for people to write computer code - each person typing at their own computer, right? Writing code involves a lot of concentration and focus, surely one person working on their own makes for the best code? That was the gut instinct we had before we tried paired programming, but it's not necessarily the case, and we've found it to be very effective for particular projects or thorny coding problems.

The way that paired programming works is that one person is the driver (the one typing) and the other person is the observer or navigator (the one looking at the screen). If you have more than 2 people you can split these jobs up further: one person can be watching the code being written line-by-line, while the other (or others) are monitoring the sense and purpose of the code as a whole. An important feature is that you swap these roles regularly; everyone should take a turn being the driver or navigator so that it's a balanced and equal experience.

Rather than one person trying to manage multiple roles: coder, checker, planner, strategy etc. these are split between the team. With your head buried in code, it's hard to keep track of everything else. Many's the time when we've puzzled over a function that's not working and had to remind ourselves: "Why do I need this again?!"

There are a number of benefits to coding together:

  • your code is less buggy. The navigator/observer can check for syntax and logic errors, which are quicker to avoid in the first place than test and then fix.

  • your code is more focussed. If one person is keeping an eye on the end goal, it helps to avoid falling into a rabbit hole of complicated code. When you're in the middle of coding it's easy to get bogged down in solving an immediate problem without thinking about how your function helps in the medium or long term.

  • your code is better quality. It's easy to fall into idiosyncratic ways of coding or only use techniques you already know. With 2 or more people involved your code is likely to be easier for others to understand and follow, and you may well end up learning new ways of working.

  • you learn new things. Paired programming is a great way to learn new functions, structures and even more broadly, approaches to problem-solving. It's an ideal way to learn from someone more experienced - as long as you take equal turns to write and direct the code. Sitting mutely by someone's side while they type like crazy is not a good way to learn!

  • shared responsibility. If you're coding on your own with no-one looking over your shoulder, it's easy to take easy short-cuts or workarounds. When you are working with someone else (especially if they have to do the typing!) you're much more likely to do things properly, even if that means generating more work for yourself. 

  • shared understanding. If your code will be maintained by others in future, it makes sense that they help build it in the first place. They will have contributed to how it was written and have a better understanding of how it works.

  • it's fun. Coding - sociable?! The common stereotype of a programmer is a solitary figure, cut off the from the rest of the world, but it doesn't have to be that way. Paired programming is a really good way to get to know colleagues.

  • team building. Again, it's not how programmers are often pictured but in reality coders do usually work as a team, and teams need to practice working and communicating together. 

  • those jobs that nobody wants. Sometimes a coding job is so big, daunting or boring that it's easy to keep moving it to the bottom of your to-do list. Paired programming can give you the motivation to tackle those jobs and finally get them finished.

You don't even need to be physically in the same room together. Paired programming works remotely, over voice and screen-sharing applications such as Skype, Teamviewer or GoToMeeting. The most important things to bear in mind are:

  • swap places regularly - everyone should get an equal turn at each role.
  • communicate! If someone in your group isn't saying much, encourage them to participate more.
  • if your group lacks experience in the language or tech you're using, recruit someone who does.
  • mix it up. Paired programming is great for some tasks, but not for every single one. 

In Code Club at Lostwithiel Primary School, Cornwall, we encouraged children to work on projects together in groups of 2 or 3. Working together the children were likely to understand more, learn more and achieve more. Plus, most important of all, it's more fun.

Have you tried programming in pairs or groups? What do you find the advantages and disadvantages are?

Tagged under: Remote working   Code   Programming   Software   Team  

Nice things people have said about us

"Mat & Kat really listen and have expertly translated my ideas and wishes onto the pages of my website. "

Debbie-Ann Champion, Achievable WellBeing