[Python-Dev] Fwd: summing a bunch of numbers (or "whatevers")

Oren Tirosh oren-py-l@hishome.net
Sun, 20 Apr 2003 04:37:18 -0400


On Sun, Apr 20, 2003 at 01:18:08AM -0700, Brett Cannon wrote:
> [Alex Martelli]
> 
> > On Sunday 20 April 2003 08:09 am, Prabhu Ramachandran wrote:
> <snip>    ...
> > In the context of Numeric use, it's quite appropriate to have sum,
> prod,
> > and the other ufuncs' reduce AND accumulate methods.  In everyday
> > programming in other fields, the demand for the functionality given by
> > sum is FAR higher than that given by prod.
> <snip>
> 
> I think part of the trouble here is the name.  The word "sum" just
> automatically causes one to think math.  This leads to thinking of
> multiplication, division, and subtraction.  But Alex's proposed function
> does more than a summation by special-casing the concatentation of
> strings.

The special case is just a performance optimization. Without it the
sum function would still return the same result. The sum function 
should work for any object that defines a + operator. 

I agree that the name 'sum' isn't 100% intuitive for use with strings 
but I can't think of any name that would be really natural for both.

    Oren