Re:Do Python developers want static typing?
by aszen on Sunday February 28, 2021 @12:26PM
(#26295009)
On your point about compiler enforcing legitimate values, the way I see it is that if u don't get the right values from the outside world you should immediately exit the program with a nice error message.
As the data moves further down into your core functions it should become more well defined and highly structured.
Basically you should parse messy data into the types you need and then you don't need to validate the data in each of your functions.
How to enforce this is a tricky problem for the compiler, maybe it's architectural pattern that can be enforced by libraries and frameworks.
In particular I would like to see the compiler enforce that you either return a legitimate value or raise an exception, and that the caller does not go down a path that calls for a value if an exception was raised. I hate that a reference can get 10 miles away before you discover there's no data there, and it being wrapped in Option or ? or a technically-not-null zero value doesn't mitigate that.