[Python-Dev] PEP 372 -- Adding an ordered directory to collections ready for pronouncement
Steven D'Aprano
steve at pearwood.info
Wed Mar 4 08:58:09 CET 2009
On Wed, 4 Mar 2009 05:23:33 pm Glenn Linderman wrote:
> The problem with the ordereddict/OrderedDict/odict is that there
> are way too many possible orderings, and without being more
> specific (InsertionSequenceOrderPreservingDictionary) people are
> doing to think "sort" when they hear "ordered".
For what it's worth, the first time I heard the term "ordered
dictionary", I assumed it would be a dict where the keys are kept in
sorted order.
But so what? Making things easy is an admirable goal, but we shouldn't
lose sight of the fact that Python is a programming language, not a
door handle. There's no requirement that every last feature is easy
to intuit for a naive user. It's okay if people sometimes guess
wrong, so long as they have opportunity to learn better.
Speaking as an ignorant and lazy programmer, being user-friendly is
one thing, but molly-coddling the ignorant and lazy is another.
Especially when it takes just a few seconds to type "import
collections; help(collections.odict)" and learn that the O stands for
ordered, and that the order is specifically order of insertion rather
than lexicographic order. Having good help text is user-friendly.
Naming the class InsertionSequenceOrderPreservingDictionary is just
dumbing down at the cost of usability. I trust this wasn't a serious
suggestion, but just in case it was, I'll point out that we have dict
instead of UnorderedKeyValueMapping. Does anyone think that people
find Python harder to learn because of that choice?
> I think FIFOdict is a reasonable abbreviation for
> InsertionSequenceOrderPreservingDictionary :)
I see your smiley, but in my opinion, the sort of programmer who can't
work out what an OrderedDict (or odict) is, given the name, the doc
string and the Internet, is going to have even more trouble working
out what FIFOdict means.
I have no strong feelings either way between odict and OrderedDict.
PEP 8 seems to demand OrderedDict, but I actually prefer odict on the
basis that an ordered dictionary feels like a fundamental data
structure like str, list and dict rather than a specialist class like
HTTPBasicAuthHandler. (I realise that "fundamental data structure" is
not a well-defined category.) I look forward to the day OrderedDict
becomes a built-in so it can be renamed odict :)
--
Steven
More information about the Python-Dev
mailing list