This sounds terribly controversial, but I would love to know /when/ the static-typing pays off compared to a looser approach like sound-gradual typing (where you basically export types at a boundary and make sure that you don't violate those).
I do wonder whether a better approach is to prove your code in some other language (say Z3, Agda, Coq) - then implement it in something else, making sure you can prove isomorphism. This has quite a few benefits; you're not tied to a constructive proof on the type-level ala Haskell, Rust, Go etc... and you can automate a large part of trivial proofs.
I haven’t quite seen another language handle it this elegantly as Python does.
Then, inside the function, you can check the parameter’s data type, and handle it appropriately. And error out immediately if the wrong type is passed in.
This allows you to operate on the data at a more logical level (what it implies), as opposed to just at the technical level (what data type it is).
For example, you can pass in a single string, or a list of strings. And your function can check the type and handle it appropriately.
In C++ and Java, because of the rigidity of the function declaration, in order to do something like this, then you would need to create multiple functions to handle each of the different types that you want to allow. Then you’d need to create a wrapper function to dispatch it to its appropriate sub function. That becomes a complete mess after a while.
When you are in a codebase where you don't know which modules have been soundly typed, and which ones are still in the 'gradual' phase.
40+ years of programming experience here + a language geek. I have for years programmed in both dynamic and static languages to find out what works best for me. My conclusion is that problems are easier to solve with statically typed languages. So clearly different languages works for different personalities.
So, some examples? Also examples where "easier" is not just "you don't need to write types". That goes without saying...
But static typing has a few key benefits:
* No searching through comments for type constraints.
* Better autocompletion.
* Better compilation.
* Better serialization/deserialization.
I do think static typing pays for itself in the long term. Sometimes, we shouldn't care about that. Engineering means managing tradeoffs: short-term velocity vs long-term performance and maintainability?