hnlmorg 2 days ago

Very true. As an author of a several multithreaded applications, I concur that unit testing thread interactions is hard and seldom exhaustive.

1
latchkey 2 days ago

It is not exhaustive because you haven't taken the effort to do it. It isn't easy, you have to write you code in a way that can be tested. It takes planning and effort to do this, but it pays off with having applications that aren't full of bugs.

macintux 2 days ago

You sound like the people who argue that, despite decades of security vulnerabilities offering evidence otherwise, C is perfectly safe if you know what you’re doing and just put more effort into it.

Technically you may be right, but it’s not a helpful viewpoint. What the world needs are abstractions that are easier to understand and program correctly, not assertions that everyone else is doing it wrong and just needs to be smarter/work harder.

latchkey 2 days ago

That's absurd, I'm not arguing anything of the sort.

If you want an analogy, I'm arguing that a condom helps prevent STD's and unwanted pregnancies. It isn't perfect, but at least it is better than not wearing a condom at all. Nobody loves wearing a condom, but we do it cause it is the right thing to do.

dymk 2 days ago

You can't prove away chlamydia or an unwanted pregnancy, but you can provably eliminate whole classes of logic errors by having more powerful type systems.

latchkey 2 days ago

100%. Compilers for the win for sure. It was a big reason why I started to write Java code and move away from PHP. This lead me to co-found Java @ Apache.

hnlmorg 2 days ago

It’s not exhaustive because complex multi-threaded software has a plethora of hidden edge cases, many of which actually fall outside the traditional remit of a unit test.

This is where other forms of software testing come into play. Such as integration tests.

latchkey 2 days ago

wtf is a hidden edge case? Is that like flying a plane with blinders on? Come on...

You write tests to cover edge cases. If you miss one, you write more tests when you come across them. This isn't magic.

hnlmorg 2 days ago

> If you miss one, you write more tests when you come across them.

…before such point you have hard to find bugs in your software.

And that’s the crux of everyone’s argument against your “just write better code” fallacy ;)

> This isn't magic.

No it’s not. That’s why people disagree with your assessment that unit tests can catch every type of bug.

If unit tests really were that magical then we wouldn’t need for other methods of tests.

I mean, do you even know what a unit test is? It’s meant to be self-contained but the problem with multithreaded code is that you can start to introduce side effects that happen outside that functions scope.

I’ve got exactly that issue right now calling OS APIs from cgo. Some of those APIs (particularly with SDL) are very thread sensitive and you cannot unit test for that because the problem lies outside that functions scope. So the only way to test for that is with e2e or integration tests instead.

latchkey 2 days ago

I didn't say "just write better code", I said write more tests. Writing those tests will produce better code.

I also never said unit tests were the ONLY tests.

hnlmorg 1 day ago

But you were ONLY talking about unit tests for catching concurrency bugs; bugs which often fall outside the scope of a unit being tested.

Nobody disagrees with your point about the importance of unit tests. But the way you present that point is more than a little naive (and that’s the polite way of putting it).

lenkite 1 day ago

> If you write comprehensive unit tests...