Hacker News new | ask | show | jobs
by dolni 877 days ago
I have written type-annotated Python for as long as type annotations have been a thing.

"Number of bugs will drastically increase" is simply wrong.

Type checking prevents bugs before they ship.

1 comments

There are numerous academic studies that show that type checking does not reduce errors in shipped code by an statistically significant amount.

Type checking mostly shows that code can be compiled successfully. The thing it was designed to do.

> There are numerous academic studies that show that type checking does not reduce errors in shipped code by an statistically significant amount.

i've read some of these studies, they don't prove much. it's typically languages with inexpressive type systems like java.

>Type checking mostly shows that code can be compiled successfully. The thing it was designed to do.

what languages are you thinking of when you say things like this? these debates are useless because one person is thinking of the type system of language X and the other person is thinking of language Y. a lot of heat but little light.

Over the years, plenty of people have wanted to show that static typing gives code correctness benefits over dynamic typing. Everyone who tries just falls flat on their faces.
again, specifics please. which languages are you thinking of?

I don't see how e.g. [1] or [2] are "falling flat on their faces".

[1] https://fsharpforfunandprofit.com/posts/designing-with-types...

[2] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

or even something as basic as non-nullable types, enforced at compile time. a clear, obvious win.

Those are some nice blog articles but the general consensus is that on a per-line basis duck typed and statically typed code have the same amount of bugs.

The duck typed code is also significantly shorter, less lines of code per software feature means less bugs per released software feature.

It's very difficult to compete against just having less code. You only needed to write 1000 lines of code instead of 3000 lines of code? Then you just eliminated 66% of the bugs.

Static typing on the other hand catches less than 1% of bugs.

So you can go for the duck typing approach and remove 66% of the bugs in your code or the static typing approach and remove 1% of the bugs in your code.

Which approach do you think works better?