[Python-ideas] Proposal for extending the collections module - bags / multisets, ordered sets / unique lists

Mathias Panzenböck grosser.meister.morti at gmx.net
Sat Jul 18 22:45:46 CEST 2009


On 07/18/2009 10:19 PM, Leonardo Santagada wrote:
> 
> On Jul 18, 2009, at 4:07 PM, Michael Lenzen wrote:
> 
>> My full proposition includes 2 new classes, 2 new abstract base
>> classes, modifying set and a new `collection` function to abstract
>> away the new multitude of classes.
>>
>> The collection function is my favorite part, you just pass it
>> parameters about the collection you want (mutable, ordered and/or
>> unique) and it returns the collection that fits without you ever
>> having to figure it out.
> 
> 
> I was silent on this because I wanted someone that has a say in this
> stuff to stop it but as you really think this is important I have to
> point out that this function is probably unaceptable, it makes code that
> much harder to read (instead of set or list I have to see each parameter
> and form on my mind what they map to) and also GvR already said before
> that he doesn't like functions that have flags that make them do
> completely different things based on those.
> 
> Multiset seems interesting, some of the ABCs you mentioned seems to be
> just over engineering (maybe they just need a better justification) but
> this function in my view is unacceptable.
> 

I don't understand what's so bad about such a collection factory. As a
programmer I don't care what class an object is. I just want an object that
behaves a certain way. E.g. I want to say: I need a random accessible
collection, or I need a collection with unique entries, or I need a collection
with a fast (near to O(1)) way to append elements, or all of the above. What
class this object will have I don't care.

Where is the problem?

	-panzi



More information about the Python-ideas mailing list