Python's simplicity philosophy

Michele Simionato mis6 at pitt.edu
Wed Nov 12 01:48:55 EST 2003


Douglas Alan <nessus at mit.edu> wrote in message news:<lcvfpqsgsk.fsf at gaffa.mit.edu>...
> C'mon -- all reduce() is is a generalized sum or product.  What's
> there to think about?  It's as intuitive as can be.  And taught in
> every CS curiculum.  What more does one want out of a function?
> 
> |>oug

Others pointed out that 'reduce' is not taught in every CS curriculum
and that many (most?) programmers didn't have a CS curriculum as you 
intend it, so let me skip on this point. The real point, as David Eppstein
said, is readability:

reduce(operator.add, seq)

is not readable to many people, even if is readable to you. 
That's the only reason why I don't use 'reduce'. I would have preferred 
a better 'reduce' rather than a new ad hoc 'sum': for instance something 
like

reduce([1,2,3],'+') 

in which the sequence goes *before* the operator. It is interesting to 
notice that somebody recently suggested in the Scheme newsgroup that

(map function sequence)

was a bad idea and that

(map sequence function)

would be better! 

Of course, I do realize that there is no hope of changing 'reduce' or 'map' 
at this point; moreover the current trend is to make 'reduce' nearly 
useless, so I would not complain about its dead in Python 3.0. 
Better no reduce than an unreadable reduce.

Also, I am not happy with 'sum' as it is, but at least it is
dead easy to read.

                           Michele Simionato




More information about the Python-list mailing list