Dont Bother Testing Just Write Perfect Code

A management AntiPattern wherein it is decreed (due to the usual schedule or budget pressures) that testing of the product will be rather limited in scope (or in the extreme case, not done at all); yet a high-quality product is expected. The rationale for this apparent disconnect is the belief that quality should be free--a natural byproduct of development methodologies (see QualityIsNotFree for more on this); and programmers who write buggy code simply are bad programmers. This is an AntiPattern because:


In a job interview I was asked how I would respond to a developer that asked "Why do you write tests? Just write code with no bugs." I floundered and eventually said "I'd need to go away and think about that one." It's a week later, and I knew the answer all along - it just took me a while to come up with it. Here's my answer:

Maybe you can write perfect code, but over the lifetime of your code it's going to be looked at, and modified by, and copied by, many far lesser programmers. They will introduce bugs, because they can't write perfect code; your tests will help catch those bugs, and stop them going live. Further than that, you're making an invalid assumption: Testing is not (just) to catch bugs. People who do test-first development are being continually forced to answer the questions "What does this class do", "How will this class be used" and "Do I really need this class anyway". Such questions are extremely valuable to system design and so test first developers end up with more modular code, with better metrics for coupling and coherence, with greater maintainability. Oh, and fewer bugs.

Now, can I wind the clock back a week so I can give this answer in my interview..? --StuartScott

I'd reply, "How does one write code with no bugs?" Well, it's clearly a ridiculous position to take. But when you're trying to win business, and also to build relationships with your customers, then you need to avoid the ego bruising response of "Don't be daft!"'


EditText of this page (last edited May 21, 2004) or FindPage with title or text search