[Python-ideas] PEP: Dict addition and subtraction
rosuav at gmail.com
Fri Mar 22 03:49:12 EDT 2019
On Fri, Mar 22, 2019 at 1:58 PM David Mertz <mertz at gnosis.cx> wrote:
> On Thu, Mar 21, 2019, 10:15 PM Steven D'Aprano <steve at pearwood.info> wrote:
>> > Of course I could learn it and teach it, but it will always feel
>> > like a wart in the language.
>> Would that wartness be lessoned if it were spelled | or << instead?
> Yes, definitely. Both those spellings feel pretty natural to me. They don't have the misleading associations '+' carries. I'm kinda fond of '<<' because it visitation resembles an arrow that I can think of as "put the stuff here into there".
Please no. The "cuteness" value of abusing the operator to indicate
information flow got old shortly after C++ did it, and it doesn't
help. With normal operator overloading, you can say "the + operator
means addition", and then define "addition" for different types.
Perhaps that ship has sailed, since we already have division between
path objects, but at least in that example it is VERY closely related.
There's no use of "<<" inside string literals with dictionaries the
way there's "/foo/bar/spam" in paths.
Dictionary merging is a form of addition. It's also related to set
union, which is well known as part of the pipe operator. Either of
those is far better than abusing left shift.
More information about the Python-ideas