On 17/10/2019 14:59:13, Anders Hovmöller wrote:
On 17 Oct 2019, at 14:26, Chris Angelico <ros...@gmail.com> wrote:
On Thu, Oct 17, 2019 at 11:08 PM Anders Hovmöller <bo...@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.
Not infrequently I use AString*AInteger or AList*AInteger. Isn't
print '-' * 80
better and clearer than
print
'--------------------------------------------------------------------------------'
# Please count these to check I got it right:-)
And of course there are many other use cases.
I don't agree. I also think + for string concat was a mistake. It's an
unnecessary source of errors.
I routinely use + to concatenate a few strings (yes I'm aware of the
performance issue adding many strings).
It's concise, clear and convenient. When I can write (toy invented example)
body = prefix + text + suffix
why should I be forced to type some more verbose and less clear
boilerplate like
body = '%s%s%s' % (prefix, text, suffix)
or
body = ''.join((prefix, text, suffix)) # Actually I missed out
a closing bracket before I tested this! I rest my case.
or
body = f'{prefix}{text}{suffix}'
or
[suggestions invited]
I would not wish to see either feature removed from Python.
I'm sure I have sometimes added a number to a string. But the TypeError
message soon puts me right.
Rob Cliffe.
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
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/KKBMWMTC3T5KP5KGMHU4G6M2YH5IR7SP/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/RHD2OUDEM4ERZY7PZ4VAQR5Y3WXX2CUN/
Code of Conduct: http://python.org/psf/codeofconduct/