Live data from Hacker News

Ask HN: Do you write tests before the implementation?

news.ycombinator.com

241–250 of 329 posts

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

#242
post #167
post #117

Earlier quoted context omitted.

At the risk of being serious for a moment, saying "please" and "thank you" are two of the lowest effort, highest reward, and plainly decent things you can do as a human.

Muh. It's OK to be one of those endless-pleasers-and-thankers, that's how you are... but stop being so fucking condescending about it! ...some of us "other kind" of people actually consider excessive politeness as offensive because it wastes time and pollutes conversations and after a certain we'll start actually being offensive with people like you, and you'll just stare amazed at how horrible people we can be! When…

I advocated saying please and thank you, so I obviously believe that the more often one utters the phrases, independent of any context, the better human being one is?

Not everyone is relentlessly virtue signaling or karma whoring, whether in IRL or on HN.

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

#243
I have had one excellent experience with TDD. I re-wrote the stubbing library Sinon in Lua, and as I wrote a feature I wrote the test first, then made the test pass. Since I wanted it to match Sinon as much as possible, the requirements were exact, meaning the tests I wrote never had to be refactored. The whole thing was really smooth and worked really well.

The issue I find is that generally we aren't writing code we know the exact requirements for, so doing TDD means that not only are you refactoring your code as you understand the problem better, but you're also refactoring your tests, which increases the workload.

Maybe that's a sign that we need to spend a lot more time designing before implementing, but I've never worked anywhere that happens enough to use TDD as nicely as my experience with my Sinon clone.

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

#244

Nope. I pretty much always find it to be counterproductive. Most of programming happens in the exploration phase. That's the real problem solving. You're just trying things and seeing if some api gives you what you want or works as you might expect. You have no idea which functions to call or what classes to use, etc. If you write the tests before you do the exploration, you're saying you know what you're going to fi…

> Be prepared to throw one away. You will anyway. Write a POC to learn then you can write tests first for production.

So, in other words... an "exploration phase" which is done prior to writing tests?

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

#245
post #64

No. I have always felt that TDD gives a false feeling of safety and satisfaction, and that it is mostly a waste of time that could be better spend optimizing and refactoring. Testing simple code is simple and therefore pretty much useless. Testing complicated code is complicated and therefore more likely to fail by making to few or to many assumptions in the test, or completely screwing up the test code itself.

A couple of takeaways from your post: - knowing your code does what you expect is a _false_ sense of safety - if something is simple, it is useless - if something is complicated, it is useless

That's the problem. You assume that because you have a couple of passed tests that you know your code. Tests are like any other code, they incur bugs at the same rate as other code, and as such can very much give a false sense of safety.

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

#246
post #58

I do, TDD gives me such a sense of confidence that now that I'm used to, it's hard not to use. > Can you describe the practical benefit? Confidence that the code I'm writing does what it's supposed to. With the added benefit that I can easily add more tests if I'm not confident about some behaviors of the feature or easily add a test when a bug shows up. > Do you happen to rewrite the tests completely while doing the…

> Confidence that the code I'm writing does what it's supposed to. With the added benefit that I can easily add more tests if I'm not confident about some behaviors of the feature or easily add a test when a bug shows up.

Isn't this just the benefit of tests, not necessarily TDD?

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

#247
Kind of, I write my code then test it via unit tests. Then I focus on achieving 100% code coverage by tuning the code and beat the devil out of it.

I have found that beating code is a great way to preserve my sleep and save the next person a headache.

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

#248

No. And also 'do you write a test for everything?'. Also No. Tried it, ended up with too many tests. Quelle surprise. There is a time/money/cognitive cost to writing all those tests, they bring some benefit but usually not enough to cover the costs. I'm also going off the 'architect everything into a million pieces to make unit testing "easier"' approach. I heard someone saying that if you write a test and it never f…

Everyone's in the confessional booth here admitting dogmatic test-first-test-everything's not so hot in practice, which is nice, but how long until it becomes safe to answer with anything other than some variation of "love testing, it's always great, I love tests, more is better" when asked how you feel about testing in interviews?

I always answer this honestly in interviews and I've always had my interviewers say they feel the same way.

I think maybe it's a thing where you're not supposed to say it, but once you do, it frees the interviewer up to admit it as well and they're happy.

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

#249
post #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.

I believe they're using it as an example of a thing that people have very strong, immovable opinions about, making it difficult to discuss. It just so happens that in the case of climate change one side is just objectively wrong, and its opinions are factually incorrect... but that just underscores the OP's use that it's impossible to discuss in public with them. They hold strong opinions in spite of overwhelming evidence against them, indicating strong feelings that will dominate any conversation you try to hold.

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

#250

Earlier 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…

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.

> So, I'm just confused in general why people wait.

Really, though?

It's simple procrastination which is always illogical.

Present-self buys temporary comfort at the expense of future-self.

Post reply on HN