←back to thread

Type checking is a symptom, not a solution

(programmingsimplicity.substack.com)
67 points mpweiher | 5 comments | | HN request time: 0.866s | source
1. crazygringo ◴[] No.45142085[source]
> Why do we need type checking at all? The standard answer is scale. “Small programs don’t need types,” the reasoning goes, “but large programs become unmaintainable without them.”

No it's not.

Type checking is a first line of defense against bugs. That's all.

It's just making sure you're not accidentally passing invalid data or performing an invalid operation.

And since the article gets the premise wrong, its conclusion that reducing complexity will make type checking "largely irrelevant" is therefore also wrong.

replies(3): >>45142327 #>>45142430 #>>45145286 #
2. motorest ◴[] No.45142327[source]
> Type checking is a first line of defense against bugs. That's all.

Exactly, and it goes way beyond that point. Static type checking turns expensive, hard-to-catch bugs that manifest only at runtime when exercising specific code paths into cheap, trivial to spot bugs that you spot at compile time.

On top of that, nowadays it greatly improved developer experience as IDEs use type hints to detect and avoid bugs even before you compile the code, and even helps autocomplete code you are typing.

We've been through this before. Haven't we learned this yet?

replies(1): >>45143563 #
3. jameson ◴[] No.45142430[source]
Right. Also same rationale goes to compile time vs runtime time checks -- catching type bugs before the program is executed
4. adamddev1 ◴[] No.45143563[source]
One of the things that drives me crazy is when people say with such brazen confidence, "we don't need type checking because our tests catch type errors." But even if your tests do catch a large amount of the errors (depending on how thorough your tests are that you've written), YOU STILL HAVE TO GO HUNT DOWN WHERE THAT ERROR CAME FROM when a test fails. Isn't it so much nicer to just have the type checker automatically show you exactly where the type error came from?
5. Agraillo ◴[] No.45145286[source]
> It's just making sure you're not accidentally passing invalid data or performing an invalid operation.

To understand that this is a big deal, one sometimes needs to face the relaxed rules of their static language of choice. Delphi (and its ancestor Turbo Pascal) allows passing untyped pointers for parameters defined as typed. This behavior is actually controlled by a setting that is probably relaxed (allowed) by default. It seems it was done for convenience when using pointer arithmetic. At some point in the past, I also started logging categories of bugs (an ad-hoc taxonomy) and, if some kind of bug appeared more than once, to do something about it (like encouraging a new habit, rule, or something similar). So, after passing wrong pointers twice in a short period of time, I made it mandatory for all sources to have only typed pointers, which required some additional typing but saved me from similar bugs further on.