When Open Classes Attack
Posted: Sun, 26 November 2006 | permalink | No comments
(... or "Why Cut-and-paste coding is a bad idea", part $bignum)
I've just spent an embarrassingly long time debugging a problem in an app that I'm converting from single-threaded to multi-threaded operation.
As a nice first step, I wrote a new test suite, and put it in a new file threading_test.rb. This file was created by copying another, similar test suite from another file.
I've since been having a lot of trouble with the new functionality, as it was throwing a lot of spurious errors. I've only just realised that this is because I defined a teardown method for my new test suite, which kinda depended on the corresponding setup method I defined. Except that I screwed up the file copy a bit, and didn't rename the test suite class name, so I was defining a teardown which was running alongside a completely unrelated setup method (the one from the original class). Kaboom!
Of course, a large part of the reason it took me so long to track the problem down is that the reported exception was vaguely threading related, and since I'm no threading guru (or even wet-eared novice, truth be told) I'd spent a long time faffing around in my threading code wondering where the problem was. Then I read the exception information really closely and suddenly all was revealed...
Post a comment
All comments are held for moderation; markdown formatting accepted.