[Python-ideas] Dict view on list of two-tuples

Steven D'Aprano steve at pearwood.info
Tue Apr 5 02:14:49 CEST 2011


Ian Bicking wrote:
> On Mon, Apr 4, 2011 at 5:56 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 
>> Data structures with an internal representation like {'a':
>>> ['1', '3'], 'b': ['2']} are not sufficient.
>>>
>> How do you know? The ordered dict implementation in the standard library
>> has an internal dict representation (or at least it did, when it was on
>> ActiveState). Why do you care whether the implementation uses a dict
>> internally, so long as the interface matches the specified (and as yet not
>> entirely decided) API?
> 
> 
> Well, I can say at least that it would not be sufficient for me to use it in
> WebOb -- I wouldn't consider it acceptable to lose the full ordering of all
> keys, as would happen if you used this structure.  It might be suitable for
> some other use, but I have no such use in mind at the moment, so diverging
> from this it would no longer be the idea that led me to start the thread ;)

You have missed my point. What makes you think that using a dict as part 
of the *internal implementation* would mean that you lose the full 
ordering of keys? ordereddict has full ordering of keys, and it uses a 
dict as the internal implementation.

The point is that you shouldn't declare what *implementation* a solution 
may or may not use, only the desired functionality.

Functional requirements: *what* the code should do
Implementation: *how* the code performs the required functions

In my experience as a manager at an IT company, one of the hardest 
lessons for technical people to learn is not to mix implementation 
details in the functional requirements. That and not spending sixteen 
hours solving a problem when the customer has only authorised three :)

You shouldn't rule out implementations based on preconceptions of what 
is or isn't possible. If somebody had declared "ordereddict must not use 
a dict under the hood", we wouldn't have an ordereddict in the standard 
library, or we'd have a sub-standard one.



-- 
Steven




More information about the Python-ideas mailing list