[Python-ideas] Let's be more orderly!

Steven D'Aprano steve at pearwood.info
Wed May 15 01:34:45 CEST 2013


On Tue, May 14, 2013 at 12:53:53PM -0700, Jonathan Eunice wrote:

> But from an app developer’s point of view, ordering is a basic, essential 
> property.
[...]
> So I propose that kwargs, at least, default to an ordered mapping rather 
> than a pure hash mapping.

Speak for yourself. I don't think it is, and while having a fixed order 
is sometimes useful, often it is not necessary. Thinking about my code, 
I cannot think of even one function or method which would get a benefit 
from having kwargs be ordered.

Frankly, with the exception of OrderedDict itself, if your functions 
would like to treat kwargs args differently based on their order, e.g. 
func(a=1, b=2) vs func(b=2, a=1), I think your design may be broken.

Keeping things ordered imposes a performance cost. I think you would 
need to demonstrate that the advantage of having kwargs be an ordered 
dict for the cases where it matters outweighs the cost for the cases 
where it doesn't matter. If somebody demonstrates that the cost of 
shifting to an ordered dict is minimal, and the advantage is 
non-trivial, then and only then would I support the idea.


> Historically, sort features were usually unstable because that’s easier to 
> implement and faster to run. Over time, stable sort has become the norm, 

I don't think that is a particularly good analogy. Stable sorting is 
intuitively correct. Treating keyword args differently according to 
their order is intuitively the wrong thing to do, at least most of the 
time.



-- 
Steven


More information about the Python-ideas mailing list