[Python-Dev] PEP 372 -- Adding an ordered directory to collections ready for pronouncement
Steven D'Aprano
steve at pearwood.info
Wed Mar 4 12:48:40 CET 2009
Glenn Linderman wrote:
>>> FIFOdict ? Yeah, that blows the capitalization scheme, way, way out.
[...]
> It is suggestive of queue behavior, and the items are a queue if looked
> at from insertion, and traversal perspectives, if I understand
> correctly.
Why is this relevant? Insertion and traversal are only two parts of dict
behaviour, whether ordered, sorted or otherwise. You can lookup, delete
or modify items anywhere in the dict, not just at the ends. Doesn't
sound very queue-like to me.
[...]
>> FWIW, PEP 372 has links to seven other independent implementations and
>> they all have names that are some variant spelling OrderedDict except
>> for one which goes by the mysterious name of StableDict.
>
>
> Well, just because six other independent implementations use a name with
> connotations that they don't live up to is no reason to perpetuate such
> foolishness, nor introduce it into the Python stdlib.
I don't believe the name is any more misleading than "dict" itself, or
"str". It is a standard well-known name. From Google:
Results 1 - 10 of about 264 for StableDict
Results 1 - 10 of about 6,880 for OrderedDict
Results 1 - 10 of about 21,700 for ODict
(I have made no effort to exclude false positives.)
Yes, if you are a Martian or somebody learning to program for the first
time, you have to learn what an ordered dict is. So what? You had to
learn what a "str" was the first time you came across one too.
> StableDict, eh? That's not so mysterious, perhaps, if you think of
> stable sorts^H^H^H^H^H (whoops, there's the wrong connotation rearing
> its ugly head again, sorry).
What does it mean to say a dict is stable? That is doesn't decay and rot
away if you leave it alone? Do items evaporate out of ordinary dicts if
you leave them alone for long enough? That once you add an item, you
can't remove it or mutate it? It's not clear what the Stable in
StableDict could mean.
> I didn't expect FIFOdict to be an extremely useful suggestion,
> but I wanted to make the point that if the name has an erroneous
> connotation, use a name that doesn't.
FIFOdict is *far* more misleading, as it erroneously suggests that you
can't (or at least shouldn't) access elements in the middle of the dict.
> From tree-walking, perhaps people would intuit the right connotations
> from InOrderDict which is no longer than ordereddict, but usually the
> tree is kept sorted too, so I'm afraid it might not be sufficient.
No, I'm sorry, that's wrong. Inorder traversal of a binary tree is
nothing like order-of-insertion traversal of a dict.
node = 'a'
node.right = 'c'
node.left = 'b'
Inorder traversal of node gives: b, a, c.
Order-of-insertion traversal gives: a, c, b.
> C'mon folks, brainstorm, don't complain about ordereddict if you can't
> come up with some alternatives for discussion!!!
There are two good alternatives: OrderedDict and odict, or as Raymond
puts it, green with pink polka dots versus pink with green polka dots. I
don't think there's much point in suggesting fluorescent orange with
brown and grey stripes as well.
--
Steven
More information about the Python-Dev
mailing list