
On 17 Oct 2019, at 14:26, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, Oct 17, 2019 at 11:08 PM Anders Hovmöller <boxed@killingar.net> wrote:
So how can you get a type error when doing
a*b
is the real question. And the answer is now obvious: any time the programmer thinks a and b are numbers but they are not.
If you start with the assumption that multiplication implies numbers, and then you see multiplication and it's not numbers, then yes, you may have problems. But why start with that assumption? Why, when you look at multiplication, should you therefore think that a and b are numbers?
Instead, start with the assumption that MANY things can be added, multiplied, etc. Then it's not a logical type error to multiply strings, add dictionaries (if this proposal goes through), subtract timestamps, etc. It's just part of coding.
I don't agree. I also think + for string concat was a mistake. It's an unnecessary source of errors.
And if you REALLY want early detection of logical type errors, use a type checker.
I would like to point out that this is wrong on many levels. The most obvious one is that this is just not how python works normally. Python is dynamically strongly typed. Not dynamically weakly typed. The vast majority of logical type errors are indeed caught when the type error occurs. This is a good thing. We don't want to be PHP or Javascript. Another flaw with this logic is that this is user hostile. We can, do and should try to catch mistakes early. Another flaw is that this argument might sort of work now but didn't work before mypy et al existed. / Anders