4 ms·
I don't think that static typing obviates the need for tests. However: * Static typing catches many kinds of bugs earlier by simply not allowing you to write i
by whakim 5y ago
I don't think that static typing obviates the need for tests. However:
* Static typing catches many kinds of bugs earlier by simply not allowing you to write incorrect code in the first place.
* No matter how good your test suite is, you're still putting the burden on the human to always remember to write tests for corner cases.
* Static typing allows you have to write many fewer tests by making invalid data unrepresentable. You don't have to write millions of unit tests of the type "what if this list is empty" if the function literally can't accept an empty list.
- joelbluminator 5y ago> Static typing allows you have to write many fewer tests by making invalid data unrepresentable. You don't have to write millions of unit tests of the type "what if this list is empty" if the function literally can't accept an empty list. We just don't write these kind of tests on our Rails codebases and we are fine. The world hasn't exploded yet anyway. If some piece of code is super tricky and sensitive then sure maybe then (though I have yet to see such a test case I think), but as a rule? No.
- whakim 5y agoI'm surprised that you never have bugs of the type "this thing is nil and I didn't expect it to be". This is by far the most common type of bug I see in production Ruby applications and it simply can't happen with something like Sorbet.
- joelbluminator 5y agoNull exceptions can even happen in Java. I wasnt refering to those.
- whakim 5y agoBut most types (besides primitives) in Java are nullable, right? Sorbet literally wouldn't let you write this code: https://sorbet.run/#%23%20typed%3A%20true%0Aextend%20T%3A%3ASig%0A%0Asig%20%7Bparams%28x%3A%20T.nilable%28String%29%29.void%7D%0Adef%20add_one%28x%29%0A%20%20return%20x%20%2B%20%22another%20string%22%0Aend https://sorbet.run/#%23%20typed%3A%20true%0Aextend%20T%3A%3A... Null is simply the most frequent example of this issue. Getting an integer rather than a string is super common, for example. Or a string instead of a date.
- joelbluminator 5y agoWhat does super common mean? Do I see these bugs once a month? No, I do not. Null exceptions are common I agree with that. For me its not enough to appreciate something like Java or Go but I understand the argument.
- BurningFrog 5y agoIf you do TDD, you catch bugs before the code is even written. I don't write a million tests. There are much better strategies for testing. Simple tests that just executes the code will catch the vast majority of type mistakes.
- whakim 5y agoIf you're just testing pieces of code in isolation, then you're either writing lots of tests or making assumptions about the kinds of input that your function could reasonably receive or return. If you're testing end-to-end, you're either writing lots of (much more expensive) tests or you're missing corner cases. I don't think that's problematic per se. Testing is just a bit of a mismatch for the problems that type systems solve.