Live data from Hacker News

Ask HN: Do you write tests before the implementation?

news.ycombinator.com

231–240 of 329 posts

Re: Ask HN: Do you write tests before the implementation?

#231

Yeah. 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...

You are not alone! In that list cleaning the kitchen is perhaps the only thing I do sufficiently diligently:(

Re: Ask HN: Do you write tests before the implementation?

#232

No. 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…

Maybe you can help me understand this. Since you don't write as many tests, that means you're not actually testing all your code branches because tests incur technical debt after all. So does this mean you test every single branch manually? just don't bother with it at all? Do you just have a few integration tests and they break and you spend a good chunk of time figuring out which logical branch broke? What happens…

Most of the typoos and obvious errors are caught by IDE thanks to intelligent code completion systems and linters. If you're writing in a compiled language - compile step might catch some of the more obvious errors too.

I manually test my current branch manually while developing and do sanity checks when it's merged somewhere. I do write tests for some cases, but rarely, only to save time when I have to test against a wide range of input parameters.

Re: Ask HN: Do you write tests before the implementation?

#233

Earlier quoted context omitted.

Enlighten me, why?

Not sure I'd call it a 'bad bad practice' for a user to do it voluntarily, but it's unnecessary. I think the above commenter is thinking about the requirement a user to change a password on a timed basis. There's been a good bit of research done in this area, and the consensus is that it just causes most people to stick a number at the end of their password anyway, making the policy completely worthless at best, but…

Do you have a link to the research you're speaking about ? My company is really about this kind of things and i'm not convinced it's really usefull

Re: Ask HN: Do you write tests before the implementation?

#234

Yeah. 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...

You’re not alone. Cleaning while you cook is the only way

Re: Ask HN: Do you write tests before the implementation?

#235
post #228

Earlier quoted context omitted.

It's weird... I'm a real lazy person. I do the dishes immediately because of this reason, it's faster and easier. I absolutely hate doing crusty dishes. So, I'm just confused in general why people wait. Its straight up less effort to do it sooner than later.

Do you have kids? I always had the same opinion until I had my daughter, and then all of a sudden there is a 2 year old who needs supervision and it becomes easier to clean up after bed time.

Procrastinating and having your attention pulled in multiple places are two different problems. You acknowledge it's easier and want to do the dishes immediately. But when you realize your two year old is painting the walls with poop or filled the toilet with all the toilet paper and tried flushing, resulting in a flood... Everyone can agree, that takes slightly more precedence than dishes.

Re: Ask HN: Do you write tests before the implementation?

#236

No. 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…

I take the perspective that tests - and particularly unit tests - are a living specification for the software that you know cannot be out of date. If you write tests in a way that you understand the business purpose of the system, you are providing a significant part of the documentation while also providing a regression suite that is automated. There are other ways to handle this. You can have a design document that…

[deleted]

Re: Ask HN: Do you write tests before the implementation?

#237

No. 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…

It's weird you bring up global warming when there is scientific consensus that it is not only happening but man made. Doesn't seem like a good analogy for something you want more data on.

Re: Ask HN: Do you write tests before the implementation?

#238
My understanding is that tests are mostly supposed to increase iteration speed - the opposite of what most comments here suggest.

> The change curve says that as the project runs, it becomes exponentially more expensive to make changes.

> The fundamental assumption underlying XP is that it is possible to flatten the change curve enough to make evolutionary design work.

> At the core are the practices of Testing, and Continuous Integration. Without the safety provided by testing the rest of XP would be impossible. Continuous Integration is necessary to keep the team in sync, so that you can make a change and not be worried about integrating it with other people.

> Refactoring also has a big effect

- Martin Fowler

https://www.martinfowler.com/articles/designDead.html

Re: Ask HN: Do you write tests before the implementation?

#239
Depends entirely on the code and the context - if it's something like a library, mostly yes. There I already know what I want the library to do, and writing the test first is a great way to get a feel for what the ergonomics are like in actual use. Also a great way to spec out what the library will and will not do. Then I write to make it work, and once the tests are passing I keep refactoring to make it neater and easier to understand, and then maybe add benchmarks and move on to optimization.

If it's an application or framework, I usually drive it from the UI, so tests are more an afterthought or a way to check / ensure something.

I find the best balance is to have thick libraries and thin applications, but YMMV.

Re: Ask HN: Do you write tests before the implementation?

#240
Sometimes.

If I'm writing something where I know what the API to use it should be and the requirements are understood, yes, I'll start with tests first. This is often the case for things like utility classes: my motivation in writing the class is to scratch an itch of "wouldn't it be nice if I had X" while working on something unrelated. I know what X would look like in use because my ability to imagine and describe it is why I want it.

There are times, however, where I'm not quite sure what I want or how I want to do it, and I start by reading existing code (code that I'm either going to modify or integrate with) and if something jumps out at me as a plausible design I may jump in to evaluate how I'd feel about the approach first-hand.

I'm short, the more doubts or uncertainty I have about the approach to a problem (in the case of libraries, this means the API) the longer I'll defer writing tests.

Post reply on HN