Ordered dict by default

Cameron Simpson cs at zip.com.au
Fri Feb 6 16:08:57 EST 2009


On 05Feb2009 01:47, bearophileHUGS at lycos.com <bearophileHUGS at lycos.com> wrote:
| [...] But even if the average performance becomes a
| little worse I think making the default Python dict as ordered is a
| positive change for Python too, because built-ins are meant to be as
| flexible as possible, even if they aren't the fastest ones or the less
| memory hungry ones

I like the builtins to be as fast as possible. If I'm not "abusing" a
built in facility I like to have the peace of mind that there's no
point being concerned about the performance of the built-in - it will be
optimal or close to it. So I feel no temptation to reimplement the wheel
and can devote my energies to the code using the wheel.

So if a dictionary has a performance weakness to add a non-widely-needed
behaviour, it's not longer a "pure" mapping and I will feel unhappy using
it.
 
| (and keeping dicts ordered decreases the surprises
| a newbie finds, makes some code cleaner, and doctests become simpler
| to write because the order of items may be more defined).

I read this as:
  - increases the unrealised assumptions about mappings in general which a
    newbie may acquire, causing them pain/complaint later with other
    mappings
  - makes some code shorter
  - making tests slightly simpler to write; it's not very hard to
    track insert order for purposes of a test short that be needed, is
    it? it seems a small gain for a loss in every production scenario

| Once the default dicts are ordered, it can be possible to add an
| unordereddict to the collections module to be used by programmers when
| max performance or low memory usage is very important :-)

I would much rather keep dictionaries as performant as possible, as a
bare mapping, and add an odict for when order matters.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

The wireless music box has no imaginable commercial value.   Who would pay
for a message sent to nobody in particular?
      --David Sarnoff's associates in response to his urgings for
        investment in  the radio in the 1920s.



More information about the Python-list mailing list