5 ms·
It matters enough that the question "does static typing dramatically reduce the benefits of unit testing" is an open question or at least seriously discussed i
by throwaway290 3y ago
It matters enough that the question "does static typing dramatically reduce the benefits of unit testing" is an open question or at least seriously discussed in the industry. All other replies are about dynamic languages.
- ska 3y agoI don't think it is really unresolved. Static languages with sufficiently rich and modifiable type systems avoid a fraction of cases where you may well want a unit test, but it's not the overwhelming majority. Merely static helps too but not all that much. So while there is a reduction, it's a stretch to call it "dramatic".
- throwaway290 3y ago> I don't think it is really unresolved Well, you are currently participating in a thread that discusses this very question so there's that... and such threads are regular on HN. I meant just that. People discuss it. What you want to say is that you have a strong opinion about it, that's OK and still possible with open questions
- ska 3y agoPeople discuss lots of things that are pretty well solved; i wouldn't equate "open question" with "lots of discussion". I guess in this context I mean that the question of static vs. dynamic in unit testing turns out to not be that hard, but the questions like "what is a unit test" and "should we unit test at all" are much muddier. Because people are confused or argumentative about the latter, they tend to pull the former into discussions that don't really have much to do with static vs. dynamic.
- deleted 3y ago[deleted]
- pfdietz 3y agoWhy isn't the question "does adequate testing dramatically reduce the benefits of static typing" asked? Why is static typing privileged by default?
- tshaddox 3y agoProbably because using a static type system gives you those benefits "for free," whereas unit tests are things you need to write and maintain. ("For free" in scare quotes because of course there are always tradeoffs between different programming languages.)
- pfdietz 3y agoThe counterargument is that for sufficiently reliable software extensive testing is needed anyway, and if you do that you find the type errors "for free". If the testing is insufficient, as in practice it often surely is, then static typing would seem to be more valuable.
- peterfirefly 3y agoIt is asked. A lot.
- mayoff 3y agoI wouldn’t say static typing is privileged, but that testing is disadvantaged, because, in the words of Edsger Dijkstra, “Program testing can be used to show the presence of bugs, but never to show their absence!” https://www.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/EWD249/EWD249.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/E...
- funcDropShadow 3y agoWe could paraphrase Dijkstra --- with some liberty -- to say, "Formal verification of programs can only show the specification is fulfilled, not that the specification is adequate."
- throwaway2037 3y ago
- randomdata 3y agoA fully evolved type system (e.g. Coq) overlaps with unit testing. But the vast majority of languages people actually use have only partial type systems that require unit tests to stand in where the type system is lacking. In practice, when you write those tests for where the type system is lacking, you end up also incidentally testing where there is type system coverage, so there likely isn't much for industry to talk about.
- kibwen 3y agoHaving static types is like having an automatic, exhaustively comprehensive, efficient unit test generator for the classes of bugs whose units tests are the most boring and annoying to write and maintain. Static types don't prevent you from needing unit tests, they free you up to focus on writing tests that are actually interesting.
- deleted 3y ago[deleted]
- throwaway2037 3y agoI agree with your post. To be more specific, you can focus more on logic and state bugs.
- throwaway290 3y agoThis, but depending on how good the type system is and how well it's used most remaining interesting tests may be integration aside from legit things like https://news.ycombinator.com/item?id=38692634 https://news.ycombinator.com/item?id=38692634
- noselasd 3y agoI'm writing unit tests in rust and c++, I'm in the same boat as the op, often finding logical errors while writing the tests. Not to mention peace of mind when you go and mess around with code you wrote 9 months ago - if you mess up or didn't think of a corner case, there's decent chance it'll get caught by existing tests.