bitwix

Tangential comments about Software Development

Sunday, September 30, 2012

Make Your Own Luck

Lucky programmers are the ones who guess how to do something right. Their colleagues, who may just have wasted hours doing something wrong, know that the difference was just luck. Tomorrow the lucky programmer may be as stuck as they are.

We've developed a data-driven system, which evaluates formulae to present a spreadsheet-like view of numbers. As well as functions like SUM, it has a function CONV which does an exchange rate conversion: CONV(EUR,1234.56) converts the second argument from Euros into the base currency. I needed an extension to convert several numbers into the base currency at once; something like CONV(EUR,1,CAD,2,USD,3,AUD,4).

I could have used CONV(EUR,1)+CONV(CAD,2)+CONV(USD,3)+CONV(AUD,4). I could have started by reading the code and adding support for the fuller syntax. I could have browsed the data to see how CONV was being used in the field, sorting through thousands of calls with the two-argument syntax.

Instead, I clicked Find in Files CONV in my test code. I saw a test case with the formula CONV(AUD,CAD,EUR,USD,1,2,3,4). Someone, perhaps me, had written the code to support a syntax able to do the job. I plugged that in and it worked. I sat still, breathing calmly, wondering why I'd just saved myself a couple of hours.

Good tests make you lucky. They can show you how a system can be used. They are in code so as a programmer I have them to hand (unlike a specification) and I can execute them to see that they do what they say they do (unlike a specification).

Phew!