We were up last this time, rather than first, and I was so impressed with the three pairs who went before us, they all paired really well and seemed to achieve what they set out to do. Joshua (one of the hosts) also decided to interview each pair just before they started coding (“so do you think you’ve got what it takes to go all the way?”) and I had no idea what to say. On the TV shows I’m sure they coach the contestants on how to respond to that kind of question, but I was too busy worried about how I was going to remember to type enough semi-colons to say anything coherent…
So, Michael produced some horrible looking C++ and led me through setting up a test so we could do “extract method” on a small portion of a hairy looking monster method. He introduced me to a technique called “sensing variable”. Basically you write a test that calls the long hairy method, and in the middle of the method just after the part you want to extract, you introduce a “sensing variable” – you assign the result of what will be your extracted method to this global. Then from your test you can check what the global contains, and write an assertion for it. The next step is to do the extract method, and the test then checks that the “sensed” variable is still the same. This should ensure that you didn’t make a mistake with the extract method, it is called, and returns the same as before.
It’s fairly simple really, but it’s the kind of thing you wouldn’t think of if it wasn’t shown to you. In a language like C++, you need all the help you can get.
Well, the judges had already awarded some very high marks to the other contestants, and our score was joint bottom, I think. Anyway, it went to audience vote between us and J.B. and Todd. They had done a teacher/pupil act similar to ours, on Eclipse wizardry rather than C++, and had raised considerably more laughs than we had. So I was a little surprised when we clearly got a louder cheer from the punters, and Jeff (the other host) announced we were through to the next round tomorrow!