Counter Class -- Bag/Multiset

msrachel.e at gmail.com msrachel.e at gmail.com
Fri Jan 23 08:37:14 CET 2009


On Jan 22, 5:54 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Giovanni Bajo <ra... at develer.com> writes:
> > * I'm not a native speaker, but why use the word "Counter"?
>
> I agree with this, the new functionality is welcome but I think
> the traditional term "multiset" or "bag" would have been better.

The term counter was what was originally approved.  At first, I didn't
like it but found that it had some advantages.  The main advantage is
that there are *bazillions* of programmers (including some very good
ones) who have never heard the term multiset or bag but have an
instant,
intuitive understanding of counting and counters.

Also, in the context of this implementation, "multiset" would not be a
good choice.  The mathematical entity, multiset, is defined with
elements
having a count of one or more.  In contrast, the Counter class allows
counts to go to zero or become negative.  In addition, I worried that
calling it a multiset would suggest that it has a set-like API instead
of a dict-like API.  With the former, you write c.add(elem).  With the
latter, you write c[elem] += 1.  So the name, "multiset" would be
misleading.

Bike-shed discussions aside (everyone has an opinion of how to name
things),
how do you guys like the functionality?  Do you find it useable in
real-world
use cases?

Raymond



More information about the Python-list mailing list