Physics of TDD

To see how Test-Driven Development is different, let’s compare it to the traditional way of programming, something I call Debug-Later Programming. In DLP, code is designed and written; when the code is “done,” it is tested. Interestingly, that definition of done fails to include about half the software development effort.

It’s natural to make mistakes during design and coding—we’re only human. Therein lies the problem with Debug-Later Programming; the feedback revealing those mistakes may take days, weeks, or months to get back to you, the developer. The feedback is too late to help you learn from your mistakes. It won’t help you avoid the mistake the next time.

With the late feedback, other changes may be piled on broken code so that there is often no clear root cause. Some code might depend on the buggy behavior. With no clear cause and effect, your only recourse is a bug hunt. This inherently unpredictable activity can destroy the most carefully crafted plans. Sure, you can plan time for bug fixing, but do you ever plan enough? You can’t estimate reliably because of unknowable unknowns.

Looking at Figure Physics of Debug-Later Programming , when the time to discover a bug (T) increases, the time to find a defect’s root cause (T) also increases, often dramatically. For some bugs, the time to fix the bug (T) is often not impacted by T. But if the mistake is compounded by other code building on top of a wrong assumption, T may increase dramatically as well. Some bugs lay undetected or unfound for years.


Figure 1. Physics of Debug-Later Programming

Now take a look at Figure Physics of Test-Driven Development . When the time to discover a bug (T) approaches zero, the time to find the bug (T) also approaches zero. A code problem, just introduced, is often obvious. When it is not obvious, the developer can get back to a working system by simply undoing the last change. T + T is as low as it can get, given that things can only get worse as time clouds the programmer’s memory and as more code depends on the earlier mistake.

In comparison, TDD provides feedback immediately! Immediate notification of mistakes prevents bugs. If a bug lives for less than a few minutes, is it really a bug? No, it’s a prevented bug. TDD is defect prevention. DLP institutionalizes waste.


Figure 2. Physics of Test-Driven Development