15.03.19 19:51, Guido van Rossum пише:
There's been a lot of discussion about an operator to merge two dicts. I participated in the beginning but quickly felt overwhelmed by the endless repetition, so I muted most of the threads.

But I have been thinking about the reason (some) people like operators, and a discussion I had with my mentor Lambert Meertens over 30 years ago came to mind.

Operators are useful because they are used for common operations. And the meaning is roughly the same in most programming languages and not only. It is very inconvenient to write any calculations using add(x, y) or x.add(y) (if you use big integers or decimals in Java you need to do this).

Concatenating strings is common enough operation too. Although Python have now many other ways to perform it ('%s%s' % (x, y), f'{x}{y}', ''.join((x, y)), etc), so using the plus operator is not strongly necessary. But this is a history. Also, the "+" operator works well in pair with the "*" operator.

But how much times you need to merge dicts not in-place?

My main objection against adding an operator for merging dicts is that this is very uncommon operation. It adds complexity to the language, adds more special cases (because "+" for dicts do not satisfy some properties of "+" for numbers and sequences), adds potential conflicts (with Counter), but the usefulness of it is minor.

Operators are useful, but not all operators are always useful in all cases.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to