Live data from Hacker News

Ask HN: Help me see why everyone seems to love TDD?

news.ycombinator.com

51–60 of 89 posts

Re: Ask HN: Help me see why everyone seems to love TDD?

#51
A lot of people love TDD. A lot of those people also misunderstand why TDD is useful. TDD is useful towards an end, but it is not the the only means of achieving that end. Let me explain what I mean:

As a personal rule, for every 1 minute I spend doing something, I make sure to spend 5 minutes thinking about what I'm doing. Does my intended solution solve the problem? Is it missing anything? Does it introduce any new issues? Does it solve the problem, but lead the code down a bad or inflexible road?

Writing and shipping code fast can be tempting, but that speed often impairs insights of what that code actually does, or what implications the code may have down the road. Spending more time thinking than doing might seem less productive, but that is only true in the context of immediate results; in the long run, being considerate and deliberate with your code will have huge payoffs.

The major benefit of TDD is that it forces developers to think about their code before writing any of it, and later reap the fruits of that deliberation. If you do that thinking anyway, without needing TDD, then the process (writing tests first) might not be as practical for you.

As with all things, it comes down to knowing your own limits, and using tools and processes help soften those limits.

If you're trying to "sell" it to your manager, keep that same thing in mind. What problems does the company experience regularly that would be solved or minimized by TDD? If the company gets along fine without it, then TDD might not be necessary. When pitching it, be sure to have actual, relevant facts ready: How many bugs make it to production? How often is a feature requested, but existing code makes it difficult to implement? Do people often find themselves asking "I wish I had thought of that earlier"?

Re: Ask HN: Help me see why everyone seems to love TDD?

#52
post #51

A lot of people love TDD. A lot of those people also misunderstand why TDD is useful. TDD is useful towards an end, but it is not the the only means of achieving that end. Let me explain what I mean: As a personal rule, for every 1 minute I spend doing something, I make sure to spend 5 minutes thinking about what I'm doing. Does my intended solution solve the problem? Is it missing anything? Does it introduce any new…

"The major benefit of TDD is that it forces developers to think about their code before writing any of it"

So does 13+ years of experience for me. Farting about setting up test frameworks doesn't usually help me think about the problem. I do sometimes do TDD, but it depends on what I am writing.

Re: Ask HN: Help me see why everyone seems to love TDD?

#53

TBH, I don't know anyone who does TDD. I only know a few handfuls of developers, but so far the only people I've briefly met that do TDD were ones selling it; the consulting company that came into the company I worked for. This consulting company tried to "teach" us TDD at the same time as I think they were learning it. Not a single developer out of the ~40 on our teams bought into it, because in almost all cases the…

I did a new "production" project where I did full TDD.

Ended up with about 200 tests.

As things go, specs changed and part of this application had to be rewritten. Most of the tests started to fail, not because the code was wrong, but because they tested for different spec. So I needed to rewrite all those unit tests again.

Sure, I catched "some" refactoring bugs, but most failed tests weren't bugs, just tests that became wrong. This made me question the whole TDD approach in production.

Re: Ask HN: Help me see why everyone seems to love TDD?

#54
post #14

TDD came out of agile programming which is also more concerned with fast delivery than NASA-style correctness. It's a tool supposed to help you go faster. If you want an agile unit test suite, it has to run in seconds, not minutes. TDD will make this very clear. If you have problems with the test suite being slow, you have to fix it! A test suite that developers actually like to run is an enormous value, maybe especi…

"If you want an agile unit test suite, it has to run in seconds, not minutes. TDD will make this very clear. If you have problems with the test suite being slow, you have to fix it!"

To me this is TDD going putting the cart before the horse. Test driven design. Except you design so that the tests run fast. And the application design, is that actually considered?

Re: Ask HN: Help me see why everyone seems to love TDD?

#55
I don't know if what i'm about to write will sell TDD to non-technical managers, or even technical manages of a certain philosopy, but--

TDD is (among other things) a way to have developers write formal (as in "machine readable") specifications for particular features of a computer program, _ahead of time_. It does this without bothering the developer with intangible (abstract, not-part-of-the-syntax-of-programming-language) late-undergraduate CS concepts like "invariant", "pre-" and "postcondition" etc.

This makes the test not only an affirmation of feature compliance, but a _reasoning tool_ in and of itself. Since tests are specifications written in the target application language and even run in the same runtime, tests can serve the dual purpose of reasoning about the abstract logic of the application as well as the implementation details of the chosen toolchain.

Now, bugs in either tests or toolchain will affect the test results, so while you can kill two birds with one stone, you might break a window in the effort. You now have to make tests for the tests and turtles all the way down.

Re: Ask HN: Help me see why everyone seems to love TDD?

#56
post #16

Well, I'm not entirely sold on TDD just yet, but after applying it for a few years now, the benefits seem to be: - Requires you to think about structure before you write the actual code. Code that is unit testable is usually better code. (but not necessarily) - Requires you to think about the scenarios that you will support beforehand. - Ensures that every file is unit tested. Without TDD you can have untested files.…

Integration tests catch more bugs.

In fact unit tests are fairly low on the scale, according to this: https://kev.inburke.com/kevin/the-best-ways-to-find-bugs-in-...

Re: Ask HN: Help me see why everyone seems to love TDD?

#57
post #54
post #14

TDD came out of agile programming which is also more concerned with fast delivery than NASA-style correctness. It's a tool supposed to help you go faster. If you want an agile unit test suite, it has to run in seconds, not minutes. TDD will make this very clear. If you have problems with the test suite being slow, you have to fix it! A test suite that developers actually like to run is an enormous value, maybe especi…

"If you want an agile unit test suite, it has to run in seconds, not minutes. TDD will make this very clear. If you have problems with the test suite being slow, you have to fix it!" To me this is TDD going putting the cart before the horse. Test driven design. Except you design so that the tests run fast. And the application design, is that actually considered?

Of course it's considered. It's not difficult to write fast unit tests if you follow the principles that make them fast. A fast test suite has lots of value, and doesn't conflict with good design—on the contrary.

Re: Ask HN: Help me see why everyone seems to love TDD?

#58
post #39
post #14

TDD came out of agile programming which is also more concerned with fast delivery than NASA-style correctness. It's a tool supposed to help you go faster. If you want an agile unit test suite, it has to run in seconds, not minutes. TDD will make this very clear. If you have problems with the test suite being slow, you have to fix it! A test suite that developers actually like to run is an enormous value, maybe especi…

Test suite being slow: you shouldn't have to run all the tests all the time, just bask the code where you are working, run the full suite and take note of the failed tests, then just run constantly these and a few more while coding. Then run again the full suite before going to lunch.

That gets annoying when you're working on something that touches several parts, and if your tests are slow altogether they'll probably be slow enough to be tedious even when running just 10% of them.

Re: Ask HN: Help me see why everyone seems to love TDD?

#59

Have you actually lived in a TDD world? Actually sat down and did the entire thing? I don't think it is worth it. Tests are good. Fire manual QA team and hire people to write automated integration tests. But actually designing your code around tests? It tends to lead to brittle systems that do a lot of dumb things. Write the code what works best, then add some tests around it where required. 40% coverage could be eno…

> Fire manual QA team

Terrible idea.

> and hire people to write automated integration tests.

Excellent idea.

I've been a part of many software projects, and unfortunately almost none of them took testing seriously enough. No, actually, none did.

I've tested software manually for years. I've found many defects I'm certain no reasonably complex automated test would have detected, because finding them was down to my global knowledge of the entire system's state or the superior ability of humans to detect patterns.

Don't underestimate what an experienced, cunning tester will suss out.

Re: Ask HN: Help me see why everyone seems to love TDD?

#60
I do sort of half-TDD if you want. I guess it's not really TDD. When I'm working on something, I always end up having to test it, so I try often to save these short functionality tests in a structured way so that they can be re-run. This often saves me from introducing problems in the future.

So it's not really test-driven, but one has to test, right, so why not just keep the tests around for later verification.

It also forces you to write code that _can_ be tested unit-wise, which is nice. I don't know if I want my development to be test-DRIVEN, but I do like tests.

Post reply on HN