Saturday, December 22, 2007

tests as stories




I've been thinking recently about comments in code and the stories that these comments tell.

For a long time, I've considered it very important for code to have lots of comments in it, after all, computer code is not just a set of instructions for a computer, it is a conversation between the developers of the code, what they were thinking of when they designed it, and where it is going.

The problem though, is that often code changes and the developers don't change the comments in the code at the same time, leading to a mismatch between the story that the code is telling and the story that the comments are telling.

I'm wondering if a way around this could be to have more descriptive comments and stories in the testing code for an application.

I've noticed that when I'm writing a program and when I'm writing tests, I'm in two different frames of mind, when I'm writing code, I'm trying to build a beautiful and fast system, and am focused on beauty, and tons of code comments sometimes obscures the beauty of the code, especially when I'm writing in a very expressive language such as Ruby.

When I'm writing tests, I'm thinking about the whole story of the application, what I was thinking when I developed the code, what I was thinking when I made changes to the code. It's a more "meta" mind space.

What do you all think?