Hacker News new | ask | show | jobs
by _ea1k 5225 days ago
The TDD issue is really the biggest for me. I've run into many developers over the years who shout how much more efficiently things would be built if we all just did that. Surprisingly few do it themselves, though, due to a "lack of time". The contradiction in that never quite hits them for some reason.

TDD has it's place, but taking it as an incontrovertible dogma is not useful.

3 comments

It depends on the person. Does writing tests help you understand the problem, and if so, does that help you solve it faster? Only you can answer that. Here's a quote from Rich Hickey that really struck home with me:

> I never spoke out 'against' TDD. What I have said is, life is short and there are only a finite number of hours in a day. So, we have to make choices about how we spend our time. If we spend it writing tests, that is time we are not spending doing something else. Each of us needs to assess how best to spend our time in order to maximize our results, both in quantity and quality. If people think that spending fifty percent of their time writing tests maximizes their results—okay for them. I’m sure that’s not true for me—I’d rather spend that time thinking about my problem. I’m certain that, for me, this produces better solutions, with fewer defects, than any other use of my time. A bad design with a complete test suite is still a bad design. (http://www.codequarterly.com/2011/rich-hickey/)

Another question to ask is does this help others understand the problem? You often don't write tests for yourself, but for other people, including the later you that has popped the problem off the mental stack long ago. Writing tests might lose you time right now, but the net gain of time saved by others may make up for it. Let me emphasize the word "may", because you might make the problem clearer by writing documentation in English rather than code. So the only conclusion is that it depends, it depends...

I agree with essentially everything that you said. The one thing that I'll add is that I was speaking specifically of Test Driven Development, not of tests in general.

The benefits of using tests as documentation come regardless of religious adherence to test-first, and in my opinion are often hindered by it. I agree that tests can make great documentation, as well as adding value for a number of other reasons (regression, etc).

I severely question the concept of writing them first in all (or even most) cases, though.

What you've constructed here is called a straw-man argument.
Nope, he speaks the truth. The only thing I have learned in development is that there is no answer that is always right (with the possible exemption that you should always use a version control system) but there are some that are always wrong. TDD does not belong in that category, and it can be a very useful tool when you know exactly what you want the code to do and just have to figure out how to get it to do that.

In general this means you will be writing mathematical or algorithmic code which can easily be separated from the rest of the system.

I don't think there is a majority of developers out there that believe that TDD is the end all be all solution to software development problems - and thereby "make programming painful". A lot of people think it applies well to a very large domain of problems and his argument doesn't address any particular scenario - it just states it's not a panacea - strawman.
taking it as an incontrovertible dogma is not useful

I dare anyone to provide any example of incontrovertible dogma as being useful.

In four words:

Always use version control.

I stand corrected and submit to your wisdom.