Archive for the 'Expressive Code' Category

TDD is not finished until the code speaks

Saturday, April 25th, 2009

A problem, and solutions that don’t seem right

I recently asked a few people to solve a little programming problem. In this problem, a number of towns are connected by one-way roads that have different distances. The programmer must write code that answers questions such as:

  • What is the distance of the path A-B-C-D?
  • How many paths are there from A to C that are exactly 4 steps long?
  • What is the distance of the shortest path from A to D?

The graph

I reviewed three different solutions; they were all valid, reasonably well written. Two had proper unit tests, while the third was checked by prints in a "main". The authors tried hard to write a "good" solution. There were no long methods; all the logic was broken down in small methods. And yet, I was not pleased with the results.

(more…)