by swift · 10y ago · 0 comments
Here's the thing: test coverage is crucial on any large project, and we (hopefully) all agree that they're worth it, but tests can be very hard to write and impose a huge development cost. Static typing helps reduce that cost by reducing the number of tests you need to write. Generally, the more powerful the type system, the more the number of tests you need to write is reduced.
It's been my experience that the development cost of static typing is infinitesimal compared to the savings of having to write and maintain fewer tests. YMMV.
Those type annotations are the tests, they're just run by the compiler. And once you realize that, you can start to ask: are these the most valuable tests to write? If I have a fixed amount of time to write & maintain tests, would that time be better spent testing things more likely to be incorrect?
Disagree slightly. Type annotations are logical propositions and the compiler proves them for you.
That is to say: Tests can only prove the presence of bugs, not absence. Types prove the absence of (type-related) bugs. They essentially give you theoretically perfect test coverage (modulo bugs in the compiler).
Theoretically perfect test coverage, for a particular class of bugs. But that class of bugs isn't the most prevalent class, nor are they the hardest class to fix. So it still is a question of, is that the best place to put development time? And beyond that—are all type annotations equally relevant, or are there some that are very valuable, and some that are less so, and so an optionally typed language would be ideal in that regard?
Well, except maybe is is? They're certainly extremely severe when they occur. (Especially if your language is weakly typed like C/C++.)
Without the proper research, who knows? (I'm only talking about my own experience, so YMMV. I'm not even sure a proper metric for a 'fair' comparison can be constructed, even in theory, so again YMMV.)
EDIT: Just curious as a point of interest: What statically typed languages do you have non-trivial experience in? This is not a gotcha, or a haha-look-a-the-noob type question. I find that the quality of the $ST_LANG has a huuuuuuuge impact on how people perceive the value of $ST_IN_GENERAL... if that makes sense.
I disagree with the idea that you need to write more tests because of dynamic typing, my claim is that the tests you have to write anyway also cover type errors. Just running your code yourself covers most type errors.
TypeScript is so much better to work with. Most of the time it feels like ES2015.