[Python-ideas] adding dictionaries
Andrew Barnert
abarnert at yahoo.com
Tue Jul 29 21:29:29 CEST 2014
On Tuesday, July 29, 2014 7:36 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>On Tue, Jul 29, 2014 at 07:22:34AM +0100, Paul Moore wrote:
>> On 29 July 2014 00:04, Alexander Heger <python at 2sn.net> wrote:
>> > D = A | B | C
>> >
>> > becomes
>> >
>> > D = dict(collections.ChainMap(C, B, A))
>>
>> This immediately explains the key problem with this proposal. It never
>> even *occurred* to me that anyone would expect C to take priority over
>> A in the operator form. But the ChainMap form makes it immediately
>> clear to me that this is the intent.
>
>Hmmm. Funny you say that, because to me that is a major disadvantage of
>the ChainMap form: you have to write the arguments in reverse order.
I think that's pretty much exactly his point:
To him, it's obvious that + should be in the order of ChainMap, and he can't even conceive of the possibility that you'd want it "backward".
To you, it's obvious that + should be the other way around, and you find it annoying that ChainMap is "backward".
Which seems to imply that any attempt at setting an order is going to not only seem backward, but possibly surprisingly so, to a subset of Python's users.
And this is the kind of thing can lead to subtle bugs. If a and b _almost never_ have duplicate keys, but very rarely do, you won't catch the problem until you think to test for it. And if one order or the other is so obvious to you that you didn't even imagine anyone would ever implement the opposite order, you probably won't think to write the test until you have a bug in the field…
More information about the Python-ideas
mailing list