Discussion:
[xplc-general] XP pays off
Pierre Phaneuf
2002-03-19 03:30:08 UTC
Permalink
I had a good demonstration of XP (extreme programming) paying off during
my recent work on XPLC.

Find the bug in this extract from UUID::fromString():

if(*str != '-')
break;
++str;

if(format1)
if(*str != '}')
break;
++str;

if(*str != 0)
break;

Could you catch it? The second "++str" should only occur if "format1" is
true (it is for skipping over that '}', but we shouldn't skip a char if
we're not looking for it!).

This bug was in my first draft of UUID::fromString(), but I had the test
already written (testing for a UUID with only a '{' at the beginning or
only a '}' at the end), so it took me about 10 seconds to find and fix
it.

Granted, the test took a bit more time to write but not *that* much (the
specific lines that test for this problem took seconds). Also, this
string parsing routine is slated for changes soon (this is just a
"correct" version, I'll make improvements later), the tests will assure
me that I am not breaking anything.
--
Pierre Phaneuf
Loading...