Hacker News new | ask | show | jobs
by pka 3800 days ago
In addition to what the others said, I'd much rather prefer good static typing (i.e. Haskell).

Especially in the prototyping phase, I do a lot of iterating and refactoring - and I mean A LOT, because I've found that this is the best way for a good design to fall out. Sometimes like 20-30% of the code get refactored, replacing core data structures and control flow.

If I ever had to rely on unit tests for this, I'd shoot myself, mainly because it would make me 1/2 times slower (because I'd have to reimplement all unit tests every time) and this would really break my flow.

Also, relying on unit tests for refactoring means that having anything short of 100% code coverage (i.e. 70-80% isn't enough) defeats the purpose of the whole thing anyway - and I've yet to see 100% test coverage in a real-world project. I realize this isn't an argument in the context of your reply (it was either test coverage or static types), but still, something to consider.

1 comments

What about tech that generated tests automatically from code and annotations? How do you think that would affect your work?
Well, this is basically what types are :)
No, not imperative types. Tests run specific data through one or more functions for a variety of reasons. Each run will have some successful or flawed effect. Different values of the same type of data can have different results. So, generating test values from specs and types automatically is different from merely typing the data or functions.

And, again, I'm talking traditional types like in Java or C++ rather than dependent types and other esoteric stuff.

Oh, yeah - something like QuickCheck [0] is great! There are Java and C++ implementations as well, though I haven't tried them. Definitely a nice alternative to traditional unit testing whenever possible. I don't know how well it mixes with unrestricted IO like in Java etc though.

[0] https://en.wikipedia.org/wiki/QuickCheck

Now you're getting the idea. QuickCheck is a good example. I was going to drop an example from safety-critical industry but there's too many now for me to find it lol. Anyway, thanks to our discussion, I did find this great page with links to surveys, list of strategies, and listings of tools:

http://mit.bme.hu/~micskeiz/pages/code_based_test_generation...

Enjoy!

Looks great, thanks!