
On Fri, Oct 18, 2019 at 01:23:42PM -0400, Ricky Teachey wrote:
i'm a -0 on the PEP.
that being said, I am sure i will probably use the hell out of it. it is very convenient syntax for mashing together several mappings:
"I really like this idea, it's great! Let's not do it!" That's why I love Python-Ideas so much. *wink*
but i'm -0 because i am very concerned it will not be obvious to new learners, without constantly looking it up, whether adding two mappings together would either:
When Python first added the dict.update method (I think that was in 1.5?) I could never remember if it kept the old values or the new. But there were a million other things I couldn't remember either, such as whether slicing was open or closed, whether the trig functions in math took degrees or radians, whether exponentiation was ^ or ** and whether I needed parentheses around calls to print or not. I still sometimes write "import object from module" instead of the other way around, and I can never remember the names of the functions to convert degrees to and from radians. Until you learn the underlying principles of the language, very little is obvious. (I pity those learning languages with few underlying principles, or many exceptions.) One of those principles is that dicts are "last value seen wins". That applies pretty much everywhere. All of these will behave the same way: d = {'age': 10} d['age'] = 11; d['age'] = 12 d = {'age': 10, 'age': 11, 'age': 12} d = {'age': 10} d.update({'age': 11}, age=12} d = {**{'age': 10}, **{'age': 11}, **{'age': 12}} Rather than learning a whole lot of special cases, there's one general case that you need to learn: updates go from left to right (or top to bottom) and all of those cases become clear. And addition will be no different: d = {'age': 10} + {'age': 11} + {'age': 12} Outside of specialist uses (in which case, you can make a subclass) the most obvious and useful result is for the last value seen to win. That's what it means to *update* a dict. It would be a pretty strange language indeed if the default behaviour was for the update method to *not* update existing values: # this would truly be weird d = {'age': 10} d.update({'age': 11}) d.update({'age': 12}) assert d['age'] == 10 # first seen wins If you learn that + means update, then everything follows from that. As for the argument that people won't remember this, I find that a weak argument. Like *literally every single feature in Python*, those who use it will remember it. Those who don't won't need to remember it. And those in the awkward middle area of using it once in a while but not enough to remember it have my sympathy but nothing else. That's why we have docs, the `help` builtin, and a rich collection of forums where people can ask "What's foo?" and people can respond "LMGTFY". We should not fear having to look things up. Nobody can remember *everything*, and the only languages where you don't have to look things up are languages like Iota and Jot which have exactly two symbols and two operations each: https://en.wikipedia.org/wiki/Iota_and_Jot but just try programming in them. "Looking things up" is an important and fundamental skill for programmers, very possibly the single most important skill of all. -- Steven