Measuring static typing in this way is a flawed strawman argument. There are so many factors involved in counting bugs that it is probably not worth even considering. The true advantages of static typing are:
- It lets the programmer find problems at compile-time, not run-time. This means you spot the problems faster leading to increased productivity.
- It allows problems to be detected that might not be found with run-time type checking until the user finds them or the system fails in production. A program that gives compilation errors is known to have bugs. A program that compiles successfully may or may not have bugs.
- Static type checking helps a lot when the programmer is working with other people’s code, either other team members on a large project, a library written by someone else, or code that the programmer wrote so long ago that they’ve forgotten its details. The static type declarations for an API declare more thoroughly how it was designed to be used. This is similar to finding bugs early but where we are talking about understanding the API rather than actual bugs.