6 ms·
TDD presents a paradox that requires split-brain thinking: when writing a test, you pretend to forget what branch of code you are introducing, and when writing
by nercury 10y ago
TDD presents a paradox that requires split-brain thinking: when writing a test, you pretend to forget what branch of code you are introducing, and when writing a branch, you pretend to forget you already knew the solution. It is annoying as hell.
You CAN indeed cover all your branches with tests afterwards. You can even give that a fancier name, like "Exploratory Testing". Of course it may be more boring or tedious, but is a perfectly valid way to ensure coverage when needed.
TDD was great for popularizing writing test first; However I much prefer the methodology called CABWT - Cover All Branches With Tests. Let the devs choose the way to do it, because not everyone likes these pretend games.
- lisivka 10y agoTDD requires you to write FUNCTIONAL test first, not unit tests you are talking about.
- nercury 10y agoI was commenting on the methodology as I heard and watched it explained by the author (Robert C Martin), as well as the way it was presented in his videos. TDD workflow is fine; it's not thinking about the pink elephant (the source code) idea that bugs me.
- lisivka 10y agoRobert Martin is author of Agile manifesto. https://www.quora.com/Why-does-Kent-Beck-refer-to-the-rediscovery-of-test-driven-development https://www.quora.com/Why-does-Kent-Beck-refer-to-the-redisc... The original description of TDD was in an ancient book about programming. It said you take the input tape, manually type in the output tape you expect, then program until the actual output tape matches the expected output.
- westurner 10y ago+1. TDD could be considered as a derivation of the Scientific Method (Hypothesis Testing). https://en.wikipedia.org/wiki/Scientific_method https://en.wikipedia.org/wiki/Scientific_method https://en.wikipedia.org/wiki/Hypothesis https://en.wikipedia.org/wiki/Hypothesis Test first isolates out a null hypothesis (that the test already passed); but not that it passes/fails because of some other chance variation (e.g. hash randomization and unordered maps). https://en.wikipedia.org/wiki/Null_hypothesis https://en.wikipedia.org/wiki/Null_hypothesis ... https://en.wikipedia.org/wiki/Test-driven_development https://en.wikipedia.org/wiki/Test-driven_development
- lisivka 10y ago+1 Right on the spot. TDD requires you to draw your target first, then hit or miss it with the code, like in science: hypotheses -> confirmation/declining via experiments -> working theory. But in practice, lot of coders are hitting a point instead, then they draw target around that point, like in fake science: we throw coin 100 times, distribution is 60/40, our hypothesis: random coin flip has 60 to 40 ratio, our hypothesis confirmed by experiment, huge savings, hooray!