News for hackers. Stuff that matters.
Re:Ask HN: Do you write tests before the implementation? by swat535 on Friday November 15, 2019 @10:39AM (#21545686)
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 if you make a typo, comment out a piece of code and forget to uncomment , etc?

I'd love to write less tests but don't know how to do it?

Re:Ask HN: Do you write tests before the implementation? by sdenton4 on Friday November 15, 2019 @11:30AM (#21546187)
Yeah, as soon as code has more than two "real" branches, I don't trust myself to manually test them all. One of them will be broken quickly if I keep hacking in a particular branch. (This is, secretly, also an argument for writing code in sufficient generality to avoid this phenomenon in the first place.)

I also never trust a test that passes the first time I run it. I am both terrible at writing correct code, and completely normal in that regard.

Re:Ask HN: Do you write tests before the implementation? by allannienhuis on Friday November 15, 2019 @02:04PM (#21547676)
I believe he's using the term branch different than you : 'alternate code path'
Re:Ask HN: Do you write tests before the implementation? by sdenton4 on Tuesday November 19, 2019 @09:49PM (#21580694)
No, alternate code path is exactly what I mean. What's the functionality I'm coding in support for today, in addition to the stuff I was supporting yesterday? How do I know the stuff from yesterday still works? TESTS!
Re:Ask HN: Do you write tests before the implementation? by LanceH on Friday November 15, 2019 @11:19AM (#21546071)
I write tests when I know the answers before to some complicated code.

A good example of this is writing some code to tell if a point is inside a triangle or not. Setting up the test case is easy with three points for the triangle, a point or two inside, points outside, etc... Writing the code is simple enough, but possibly prone to flipping a sign for a slope, or maybe translating the equation wrong.

If I'm writing a web app, I just don't bother to write them before hand. I mostly code until I get what I want and then write the test. I think of this as "nailing it in place". I want to make sure through the test that this code continues to produce what I expect. I'll write as many tests as I feel are necessary but probably not explore every branch.

Re:Ask HN: Do you write tests before the implementation? by _-o-_ on Friday November 15, 2019 @11:34AM (#21546228)
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? by ggregoire on Friday November 15, 2019 @02:08PM (#21547731)
> What happens if you make a typo, comment out a piece of code and forget to uncomment , etc?

Thanks god this is handled out of the box by any compiled language. I can't imagine myself writing tests to catch non-logical bugs.