From: Avdi Grimm Date: 2008-08-16T05:48:49+09:00 Subject: Re: BDD and TDD - What are they for? On Fri, Aug 15, 2008 at 4:35 PM, Shadowfirebird wrote: > I agree that the overhead is extra development time. After doing TDD/BDD for, oh, five years or so, I'm convinced that the "it takes longer" argument is a red herring. It may be true when you're first learning TDD and it takes you awhile to work out how to properly test something. But I've found that once I internalized testing my coding velocity actually *increased*. And more importantly, it became much steadier. Non-TDD projects are often marked by a very fast initial ramp-up, then velocity starts to decline, and then eventually they hit a wall where every change seems to take 2-5 times as long as it should because of all the unintended consequences. TDD projects, by contrast, retain about the same speed from start to finish. Write test; watch test fail; make test pass; refactor; repeat - it's a rhythm that stays constant no matter how large the codebase. I've also found that for me, personally, TDD reduces my initial startup time. In the past I used to spend a lot of time trying to dream up the "right" object model to fit the project, and I'd have a hard time actually figuring out where to dig in and start coding. And then when I did dig in for awhile, it would suddenly occur to me that I'd failed to account for something basic and I'd realize I needed to re-tool my design. And of course the subsequent refactoring would be prone to breakage because I had no regression tests. When I'm doing TDD, all I have to think about to get started is the simplest possible unit of concrete, testable functionality. I make that work the simplest possible way, and then move on to the next simplest case. As soon as I find myself duplicating code I refactor. Out of this rhythm the "right" design emerges, a piece at a time - as it is needed. And there's no wasted time at the beginning trying to figure out how to architect for the future. Which is all to say why I find any project over, say, a hundred lines of code actually goes *slower* without TDD/BDD. -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com