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:
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:
- create a new mapping of the type `type(mapping1)` with the
conflicting
values from
dict1 having precedence
- create a new mapping of the type `type(mapping1)` with the conflicting values from
dict2 having precedence
-
create a new `dict` with the values from
dict1 having precedence
-
create a new `dict` with the values from
dict2 having precedence
similarly, it is not obvious what += does:
- add the contents of
mapping2 to
mapping1, but with existing values from mapping1 taking precedence
- update mapping1 with the contents of
mapping2, including updating of values from mapping2
there is no question this will be very challenging for many new coders. NONE of the above choices are intuitive, even after it is explained to you. and if you haven't done it in a while, you will have to go and look it up. it will be a real head scratcher for a LOT of people, and a big source of bugs.
on the contrary: it becomes very intuitive to a new user why + for mappings does NOT exist once it is pointed out that there is the issue of reconciling key-value-pairs conflicts to consider. this produces an "ah ha" moment, leading to a deeper understanding of how mappings are so different from lists/tuples.
list, tuple, and string addition, on the other hand, are inherently intuitive. once you learn these, you pretty much never look up
what they mean
again (except when you try to add a list to a tuple and get an error, or try += with a tuple or string).
Rick.