Friday, May 21, 2010

Kata Two: The Pair Combinator

This is the second in a series of code katas prepared for an internal code dojo I host for the ASP.NET QA team. I share it hoping that others will practice it, and then share their own experiences in the comments. What's a code kata? I'll let Dave Thomas, who coined the term, explain its meaning.

Per request, I will target client-side JavaScript for our first few code katas, so that jQuery (or another JavaScript framework) may be used. While such a target is somewhat limiting, you can easily adapt this kata to other languages, frameworks, or environments.

I consider pair programming a fundamental part of the practice of crafting software. It's not as critical to me as, for instance, test-driven development, but I will always pair when possible. While I might not force pairing on an engineering team, I think it's quite reasonable to require some pair programming in the dojo. So I've decided that the dojo's middle hour (of three) will be paired repetitions (and pairing is certainly permissible in the first and last hour as well).

I also encourage the so-called practice of promiscuous pairing, which is changing your pairing partner frequently, after short periods of time.This works very well in a code dojo, thanks to the repetitive nature of code katas. But my experience is that, if you leave pair rotation and combinations up to folks, they tend to stay with their current partner too long. I decided to assign pairs during the middle hour, and that gave me the idea for the second kata: The Pair Combinator.

The Form

Write a web page, using only HTML and client-side JavaScript, that takes as input any number of programmer's names and the number of pairings, and produces as output pair combinations, duplicating combinations only when needed..

The manner by which input is captured, and output is displayed, is left to your creativity, provided it can be accomplished in HTML and client-side JavaScript alone.

You may use a JavaScript library, such as jQuery. You must practice TDD. You may ask anyone in the dojo to pair with you; if they aren't already paired, they must agree.

The Focus

There are several facets of this kata on which you could focus:
  • TDD
  • The user interface
  • The combinatorial algorithm
  • Manipulating the page with JavaScript
Of course, you don't have to focus on just one facet, but I found it helpful to be very deliberate and explicit about what I was focusing on for each repetition. Even though this is a relatively small problem (and page), there are many different ways to craft it. I think it's important to focus on that freedom, and the room it affords for iterative improvement. For instance, I've written discussion forums ten or more times during my career, and each time what I produce is better in some way than the last. So focus keenly on how you can improve iteration-to-iteration, in one or more of the facets.

Repeating the Kata

As with all katas, I suggest you delete all the code, both unit tests and product, between repetitions.

I think this kata is a good candidate for a time limit. On the first practice, take as much time as you need to finish. On subsequent repetitions, give yourself less time, and then shave more and more time off the limit until you can't quite finish. (And, as with any timed kata, it's important not to rush, sacrificing the quality of the form and action.)

Other ideas:
  • Try a new JavaScript framework, or none at all, for a repetition.
  • Try different implementations; not only in code, but also in the user interface (for instance, displaying results in a table versus a list).
  • Think about missing features that still stay true to the page's purpose.
Cheers,
Drew (twitter.com/anglicangeek)

If you practice this kata, please share your experience in the comments.

No comments:

Post a Comment