Most projects combing "discovery" with "development" making up-front test writing a poor use of time.
Ask HN: Do you write tests before the implementation?
211–220 of 329 posts
Re: Ask HN: Do you write tests before the implementation?
#212Re: Ask HN: Do you write tests before the implementation?
#213I almost never write tests for personal projects, but 100% of the time when working in a team. IMO, tests are not here to prevent bugs, but they are part of the developer documentation: a coworker must be able to make any change they want to my code without asking me anything, and tests are the biggest part of that.
Re: Ask HN: Do you write tests before the implementation?
#214Earlier quoted context omitted.
It's a weird quirk of the brain how easy it is to wait until the food hardens onto the cooking utensils before cleaning it (sometimes needing a hammer and chisel to remove it) rather than just rinsing it off immediately with water. Yet, despite knowing this, picking the former route every damn time anyways. If you're like this, try putting on some small bluetooth headphones. Now cleaning the dishes just becomes a way…
Every time I clean right after I cook I'm stunned by how quick, easy and painless it is. You know, the two times a year I actually do it.
Re: Ask HN: Do you write tests before the implementation?
#215Re: Ask HN: Do you write tests before the implementation?
#216Re: Ask HN: Do you write tests before the implementation?
#217No. Tests are like any other code. They incur technical debt and bugs at the same rate as other code. They also introduce friction to the development process. As your test suite grows, your dev process often begins to slow down unless you apply additional work to grease the wheels, which is yet another often unmeasured cost of testing in this fashion. So, in short, I view tests as a super useful, but over-applied too…
There are other ways to handle this. You can have a design document that is continually updated. Some teams can do this well. You can use literate programming a la Knuth. (Many code bases have abbreviated forms of this.) You can assume that the small number of developers who have been around for these decisions will never leave the company and forgo all of it. (I do not recommend this.)
So, what is your preferred alternative to unit tests as a specification? (And if your set of unit tests don't provide clarity to the source code, that may be a source of the frustration.)
Re: Ask HN: Do you write tests before the implementation?
#218The other place it works well is code written as a pair - with one member writing tests and the other writing the implementation - the challenge is on to pass the buck back to the other pair member - i.e. find the obvious test that will cause the code to fail / find a simple implementation that will cause the tests to pass. This is great fun and leads to some high-quality code with lots of fast tests.
The benefit of TDD is that your coverage is pretty high - and you aren't writing anything unnecessary (YAGNI).
I don't think I have ever rewritten tests that I have written (TDD or otherwise). They might get refactored.
TDD doesn't work so well when you only vaguely understand what you are trying to do. This is not a coding / testing problem - get a better vision - prototype something perhaps - i.e. no tests and very deliberately throw it away.
Re: Ask HN: Do you write tests before the implementation?
#219I rarely practiced TDD until I started working on a piece of software that could take anywhere from under a minute to an hour to finish running. This means I must be able to isolate the specific portion of code effectively to save time and focus on the problem at hand. The APIs for this model are well written so I can recreate a bug or test out new code effectively by stitching some APIs in a unit test. It's incredibly helpful in that sense.
Re: Ask HN: Do you write tests before the implementation?
#220Yeah. I also floss every day, clean up the kitchen as I cook, keep off-site backups of my personal data, call my mother regularly to thank her for raising me, read the terms and conditions to online services, keep an up-to-date to-do list, and change all my passwords once a month.
Suddenly I feel very lonely for the fact I do actually clean the kitchen during and right after cooking...