On 2020-09-01 07:24, Steven D'Aprano wrote:
Operator overloading is a thing, so if you want `a + b` to mean looking
up a database for `a` and writing it to file `b`, you can. But the
blessed use-cases for the `+` operator are numeric addition and sequence
concatenation.
Anything else is an abuse of the operator: permitted, possibly a*mild*
abuse, but at best it's a bit wiffy.
I don't agree with that at all. I see the operators as abstract
symbols indicating vague areas of semantic space. Any operation that
involves "combining" of some sort is a fair and non-wiffy use of `+`.
Any operation that involves "removal" of some sort is a fair and
non-wiffy use of `-`. And so on. For instance, some parsing libraries
use `+` or `>>` to indicate sequences of syntactic constructs, and
that's great. (I actually think that this flexibility should be more
clearly expressed in the Python docs, but that's a separate "idea" that
I'll have to post about another time.)
For me the equally important (or more important) question is not what
an individual operator in isolation means, but how a given type
coherently organizes the operators. In other words, it's not enough to
have `+` defined to mean something sensible for a given type; the type
must assign its operations to operators in such a way that you don't get
confused about which ones is `+` and which one is `*` and which one is
`>>` and so on. Similarly, even if a particular use of `+` seems odd
conceptually on its own, it can still be excellent if it fits in with
the overall scheme of how operators work on that type.
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
_______________________________________________
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/FFPE6MHLZOAVDGF2JUFSISIEI6P5B22E/
Code of Conduct: http://python.org/psf/codeofconduct/