DevOps Zone is brought to you in partnership with:

I was previously the Technical Director for EVE Online at CCP Games in Iceland. Before that, I worked as a Senior Technical Artist at BioWare Austin on Star Wars: The Old Republic. I am the author of Practical Programming in Autodesk Maya. I also founded www.tech-artists.org. Rob is a DZone MVB and is not an employee of DZone and has posted 49 posts at DZone. You can read more from them at their website. View Full User Profile

TDD via Tic-Tac-Toe

12.31.2013
| 13425 views |
  • submit to reddit

For the last few years, I’ve done a fair bit of teaching of TDD, usually 1-on-1 during pair programming sessions but also through workshops. I’ve tried out lots of different subject matter for teaching TDD, but my favorite has been Tic-Tac-Toe (or whatever your regional variation of it is). It has these benefits:

  1. It’s a game. People like programming a game. Learning through games is good. It also reinforces the idea of ‘testability.’ A number of times I had students combine the ‘playing’ of the game with the ‘logic’ of the game. Teaching them to split out the algorithm from the input/driver was a useful exercise.
  2. It’s not trivial. It is a problem with some real meat that can be solved in a number of different ways. It’s significant enough that a real design and architecture emerges, unlike TDD for a single function. A a bonus, the diverse answers make it fun to teach because I keep being led to new solutions by students.
  3. The rules are just right. Simple and clear. It has a clear ‘happy path’ and ‘unhappy path’.
  4. It’s bounded. You can know when it’s good enough, but there are also endless exceptions to check if you want. Which is a great way to teach people to know when something is complete enough.
  5. It has no dependencies. I prefer not to introduce people to TDD and mocking at the same time.

In the workshops I ran, we did a ‘mob programming’ of a Tic-Tac-Toe game, and then students paired up to develop an AI. While the AI was fun, it was developing the game that was probably a better exercise. And like I mentioned already, I’ve done lots of introductory TDD pairing sessions using it, recently with someone interviewing here which is when I think the Tic-Tac-Toe game really proved itself a successful subject matter. I highly suggest you give Tic-Tac-Toe a try if you’re looking for a way to demonstrate/teach TDD to someone.

If you’re interested, the code and slides I created for the workshops is here: https://github.com/rgalanakis/tddtraining I may make a blog post in the future with some more detail about how the workshops went, if there’s any interest.

Published at DZone with permission of Rob Galanakis, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Serge Bureau replied on Mon, 2014/01/06 - 9:27am

very interesting approach


Thank you

A Johny replied on Wed, 2014/01/08 - 9:31am

Im not from USA and I dunno what is TDD. It is very arrogant approach dont explain what TDD is.

Rob Galanakis replied on Wed, 2014/01/08 - 10:04am

Serge: Thanks!

Johny: TDD is Test Driven Development. A simple google search would tell you that much but I'm sorry for not writing out the abbreviation.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.