On Mon, Mar 8, 2010 at 4:21 AM, Steven D'Aprano <<a href="mailto:steve@remove-this-cybersource.com.au">steve@remove-this-cybersource.com.au</a>> wrote:<br>> On Sun, 07 Mar 2010 22:31:00 -0800, Raymond Hettinger wrote:<br>
>> On Mar 7, 5:46 pm, Steven D'Aprano <st...@REMOVE-THIS-<br>>> <a href="http://cybersource.com.au">cybersource.com.au</a>> wrote:<br>>>> Given that Counter supports negative counts, it looks to me that the<br>
>>> behaviour of __add__ and __sub__ is fundamentally flawed. You should<br>>>> raise a bug report (feature enhancement) on the bug tracker.<br>>><br>>> It isn't a bug.  I designed it that way. There were several possible<br>
>> design choices, each benefitting different use cases.<br><snip><br>>> Instead the choice was to implement the four methods as multiset<br>>> operations.  As such, they need to correspond to regular set operations.<br>
><br>> Personally, I think the behaviour of + and - would be far less surprising<br>> if the class was called Multiset. Intuitively, one would expect counters<br>> to be limited to ints, and to support negative counts when adding and<br>
> subtracting. In hindsight, do you think that Multiset would have been a<br>> better name?<br><br>Of course I'm not Raymond, but I'd encourage reading the original announcement thread where that and related issues were discussed:<br>
<a href="http://mail.python.org/pipermail/python-list/2009-January/1189466.html">http://mail.python.org/pipermail/python-list/2009-January/1189466.html</a><br><br>To summarize the arguments against "Multiset":<br>
* the API is primarily dict-like, not set-like<br>** related to this, len() and .items() don't behave in what is arguably an "intuitive" way for multisets<br>* the API allows for negative counts; sets don't normally allow negative multiplicities<br>
<br><div>The same pretty much also goes for why "Bag" wouldn't be an appropriate name.</div><div><br></div><div>Finally, it leaves the names available for when a proper Bag/Multiset is added. :)</div><div><br>
Cheers,<br>Chris<br>--<br><a href="http://blog.rebertia.com">http://blog.rebertia.com</a></div>