3 ms·
While there may be some correlation between some static typing and less bugs, there definitely isn't a linear relationship: stronger type system => fewer bugs.
by simiones 5y ago
While there may be some correlation between some static typing and less bugs, there definitely isn't a linear relationship: stronger type system => fewer bugs.
In particular, strong types past some point start exploding code complexity for any kind of polymorphic code. My favorite example is adding strong typing to linear algebra operations, via units of measure for each element of a matrix. Try to find a library that can multiply matrices where each element can be a different physical quantity (of course, validating first that the two matrices can actually be multiplied) - say, multiplying (1m 2s⁻¹) * (2s⁻¹ 1m)ᵀ = 2m/s + 2m/s = 4m/s; but not allowing (1m 2s⁻¹) * (2m 1s⁻¹)ᵀ, since it would be 2m² + 2s⁻².
Even if you can find such a library, it will be significantly more complex than an equivalent linear algebra library that is less strongly typed (one that only handles matrices of numbers, without units of measure).
- the_af 5y agoI didn't claim there is a linear relationship. It's enough for me that there is a relationship. The OP asked "what's the use case" and I gave him several that ring true to me. Whenever I write Python , I wish I was writing Haskell. No need to ask about artificial examples of linear algebra; just my boring day to day code in Python would benefit from having Haskell's type system. And yes, I do know about static typing for Python -- I find it's worse, tooling and effectiveness wise, than an actual static type system.
- simiones 5y agoWell, GP was asking about Haskell vs Rust, not Python; and the discussion before was about Haskell vs Java as well. And the example I gave is not entirely artificial - units of measure are often measured as an advantage of strong type systems, something that could potentially avoid the Ariadne disaster, and I find this common example unconvincing.
- the_af 5y agoThe GP also mentioned Python in another comment, and specifically asked "what about strong type systems", which makes the comparison to Python relevant. > something that could potentially avoid the Ariadne disaster Haskell or any language with modern static typing would definitely have helped. You wouldn't be mixing unit types and confusing them like it happened (if I remember correctly) with the Ariadne. Would it have been enough? I don't know! But it would have helped! Any measure of static and dynamic analysis would have helped for mission critical software, and it's evident the Ariadne had some serious deficits in this regard.