CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jean-Paul S. Boodhoo

Develop With Passion

TDD is like paying using cash!!

I just had an awesome comment made on my unit testing post by Tom Opgenorth. It was so good that I though it deserves a post in its own right!! Here it is:

In trying to explain the "why" of TDD, I like the example of paying cash vs borrowing money.

Using TDD is paying cash.  You shell out the time (money) now, and all is good.  Your account is clear.

Without TDD it is like borrowing money to buy something.  You get what you want but there will come a time when you have to settle your debt, usually with interest.  

From a code perspective, this interest is usurious:  wasted time spent digging through a debugger, hoping that a breakpoint was set a the right place in code so you can see the error happen.

Awesome!! Thanks Tom.


Published May 23 2007, 10:53 AM by bitwisejp
Filed under:

Comments

Fregas said:

what you are saying is that NOT using TDD is "Technical Debt",  a term coined by Ward Cunningham.  

www.martinfowler.com/.../TechnicalDebt.html

I personally have not used TDD very much, but i would suspect that for small, simple projects, TDD is overkill because there is very little technical debt to be accrued, especially if you have strong developers.

# May 23, 2007 3:08 PM

Matt Hornsby said:

@Fregas

Even if TDD is overkill in the "Technical Debt" department for small, simple projects, you still take away other valuable things from using TDD.

# May 23, 2007 3:19 PM

wwfDev said:

I liked this comparison :-), and to add some similarities: When you want to buy something, and want to pay with cash, you have to save up over some time - i.e. it's going to take a bit longer until you get the goods - whereas if you borrow you will get the goods sooner;  With TDD the initial release will be a bit later than if you just coded and delivered - but when you deliver it feels sooo much better!

# May 24, 2007 4:30 AM

Fregas said:

@Matt Hornsby:

Like what?

# May 24, 2007 9:39 AM

Tom Opgenorth said:

@Fregas

I guess it depends on your definition of small/simple, but I think I know what you mean.

Personally, I find that a lot of small/simple projects end up growing/expanding, and that is when the TDD comes in handy.  I can make these enhancements with less pain.

# May 24, 2007 10:23 AM

Bob said:

As @Fregas said, small projects often grow (or get re-used), and this a often where simple, purpose-built components get misused and abused.  

Using TDD even on the simple items provides a solid set of regression tests to help prevent this "parasitic" growth from breaking the original logic.

Also, I find that creating exception cases where good programming practices can be skipped causes more harm than good down the road, like when some developer decides to move that line between "simple" and "not simple"

# May 24, 2007 11:18 AM

Ben said:

Remember, their is a difference between TDD and having a lot of tests.

TDD might be overkill ( or not your preference), but tests are a good thing no matter how small your project is.

# May 24, 2007 11:59 AM

Wayne Mack said:

The purpose behind TDD is not to develop regression tests, though this is a nice side effect.  The purpose of TDD is to provide a disciplined approach to writing the code.

TDD forces you to write code in very small increments.  It forces you to think carefully about the small piece of functionality that you are about to write.  I find that it is quite rare that my initial code fails the test (I'm not counting the pre-code run of the test).  This means I am getting the code written correctly the first time and avoiding debugging sessions and interminable integration or final test sessions.

TDD is not about testing - it is about writing the code correctly.

# May 25, 2007 8:49 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!