Ping-Pong Programming: Enhance Your TDD and Pair Programming Practices

[article]
Summary:
Team player Dave Hoover wants to share a software development practice he enjoys. It emerged from the practices of extreme programming as a competitive yet simultaneously collaborative practice. Dave has found that this practice promotes the flow of knowledge between software developers better than any other practice he has experienced. As you might have guessed from the title of this week's column, this practice is called ping-pong programming, or P3 for short.

Ping-pong programming (P3) is an offspring of two well-known extreme programming practices: pair programming and test-driven development. These practices by themselves promote intra-team knowledge sharing. But this is extreme programming, and we like to push the envelope, right?

I experienced a precursor to P3 when I visited Object Mentor in 2002. I was attending their Java Language Immersion and I was the only student of Micah Martin for the entire week. We had a great time. As we began working through the payroll exercise, Micah started by writing a test and sliding the keyboard over to me. I then tried to make it pass. At first, I took giant leaps ahead of him, coding far more than it took to get to a green bar. He patiently watched me as I stumbled around, often getting lost down rabbit holes. Periodically, he drove for a moment, doing something absurdly simple to get the test to pass.

I started getting a feel for how easy it was to take small steps. And I started to enjoy taking as small a step as possible, which led Micah to write more rigorous tests. This felt like a great way to combine pair programming with test-driven development. I took the technique back to work with me and immediately tried it on my XP pilot project. It was met with mixed reviews. Some programmers resisted the idea that they would be writing tests while someone else did all the coding.

Fast forward to the summer of 2004: my first project at ThoughtWorks.

Aslak Hellesoy had just joined our project. One fine Michigan morning, I had the good fortune to pair up with him. After a quick analysis of our task, he whipped together a brief test case and we watched it fail. Aslak slid the laptop over to me and prompted me to pass the test. I smiled, wondering whether this technique had spontaneously popped up on different continents (Aslak was based in the UK). I quickly passed the test and slid the laptop back to Aslak. He immediately slid the laptop back and prompted me to write the next test. I struggled to pick up on where he was headed with the first test, but eventually slid the laptop back to him with a failing test.

We followed this cycle all morning. It was an awesome way to work with and learn from an exceptional developer such as Aslak. This back-and-forth style of development became the standard way we developed together on the project. A few weeks later, I was once again fortunate enough to pair program with another exceptional programmer: Dave Astels.

The task ahead of us was not an easy one. We needed to integrate most of the tasks I had completed during the iteration, tying them together in two different contexts. After we had acquired our ritual morning coffee, Dave started us off with a test case [ping]. I was feeling a little grumpy (and lazy) and I passed the test by hard-coding the value with which Dave's mock object was expecting to be called. Then I wrote a slightly more rigorous test in order to force Dave to implement the code that he had tried to get me to write [pong]. He chuckled (as if to say I was in over my head), whipped together the necessary code, and wrote the next test--lickety-split [ping].

The morning went by very quickly as a rhythm developed in our pings and pongs. Any time either of us passed a test we looked for opportunities to remove duplication or make our intentions more explicit in

About the author

Dave Hoover's picture Dave Hoover

Dave Hoover spends his days struggling to keep up with his fellow ThoughtWorkers, his wife, and his three children. He enjoys learning about and contributing to the craft of software development. Dave used to have a respectable job as a family therapist. He still wonders how he got here. You can read Dave's blog.

StickyMinds is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!

Upcoming Events

Sep 22
Oct 12
Nov 09
Nov 09