[Python-ideas] OrderedCounter and OrderedDefaultDict

Sven R. Kunze srkunze at mail.de
Thu Oct 22 18:09:04 CEST 2015


On 22.10.2015 03:11, Terry Reedy wrote:
> On 10/21/2015 1:41 PM, Sven R. Kunze wrote:
>> The "superclass" is not "massive" at all. It is even slimmer as
>> orthogonal aspects are refactored out into separate entities. In fact,
>> it makes it even easier to test and maintain these separate aspects (the
>> core dev should be interested in that). Furthermore, it's, of course, up
>> to debate which aspects should be injectable and which are not.
>
> The dict class itself is, in a sense, a poor example for this 
> discussion.  It is a critical part of Python's infrastructure, 
> involved in a large fraction of executed statements.  It therefore 
> needs to be as fast as possible.  For CPython, this means a heavily 
> optimized C implementation that disallows injection and that takes 
> shortcuts like bypassing method lookups.  This makes the usefulness of 
> subclassing limited.

The discussion *is* about dict:

normal_dict = dict()
ordered_dict = dict(order=dict.order_by_insert)
sorted_dict = dict(order=sorted)
sorted_default_dict = dict(order=sorted, default=int)

Why couldn't dict() or{} redirect to the super-fast built-in 
C-implementation whereas dict(order=sorted, default=int) redirects to 
some more feature rich one?

As you see, I for one don't see a contradiction between performance and 
features.

Best,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151022/b1f99eec/attachment.html>


More information about the Python-ideas mailing list