Hacker News new | ask | show | jobs
by randomdata 780 days ago
> I didn't say it catches all bugs.

It is always telling when someone starts getting worked up about something, especially when that something wasn't even said or implied.

> Also the fact static typing eliminates entire classes of bugs means you need to write far fewer tests.

You don't need to write any more tests in the absence of static types. The purpose of testing is not to act as a replacement for static types and if you find yourself writing tests just for the sake of testing types, you know you're doing something horribly wrong. But, you necessarily have to encode type information into the tests in order of them to execute. After all, if that wasn't the case, you wouldn't even be able to catch bugs with a type system. As such, you gain that indirectly.

> I've seen Python tests that literally fed different types into functions and verified that they accepted them. What a misguided waste of effort!

Sure, I've seen developers do all kinds of stupid things too. In fact, give them Typescript and they will just litter the code with `any` everywhere – something I've witnessed far too often. There is no technical solution to bad developers. Was there supposed to be some meaningful takeaway here?

1 comments

> You don't need to write any more tests in the absence of types.

To achieve the same level of quality, yes you absolutely do. This is actually a fairly fundamental fact about static typing. Static typing is a weak form of formal verification, or equivalently formal verification is just really really strong static typing. Clearly you don't need to write as many tests for formally verified code. The same is true (to a lesser extent) for "ordinary" static typing.

> Sure, I've seen developers do all kinds of stupid things too.

It's not stupid if you have a static typing system available! The stupidity was relying on tests to verify types, instead of ... you know, the thing whose whole purpose is to verify types.

> This is actually a fairly fundamental fact about static typing.

If you have a complete type system. But as we are specifically talking about partial type systems, you have to already cover all your bases for where the type system is lacking, and by virtue of that you are going to overlap with what the type system also covers.

> It's not stupid if you have a static typing system available!

There is no reason for it, static type system or not.

> If you have a complete type system.

Nope. You don't need a Turing complete type system.

Complete, not Turing complete. How on earth did you manage to add an entire new meaning into the discussion that wasn't there before? I'm getting flashbacks of the earlier comment that started randomly going off on some weird tangent about how tests don't catch all bugs.

Anything to avoid the actual topic at hand, I guess?