reduce()--what is it good for?

Robin Becker robin at jessikat.fsnet.co.uk
Sat Nov 8 13:01:09 EST 2003


In article <TE9rb.112818$e5.4102715 at news1.tin.it>, Alex Martelli
<aleaxit at yahoo.com> writes
....
>I will gladly concede that reduce IS hard to beat if your purpose is to
>write complex, brittle, hard-to-maintain code.
>
>Which is exactly why I'll be enormously glad to see the back of it, come
>3.0 time, and in the meantime I heartily suggest to all readers that (like,
>say, apply) it is best (_way_ best) avoided in all new code.
.... 

I don't understand why reduce makes the function definition brittle. The
code was brittle independently of the usage. Would a similar brittle
usage of sum make sum bad?

I really don't think reduce, map etc are bad. Some just don't like that
style. I like short code and if reduce, filter et al make it short I'll
use that.

As for code robustness/fragility how should it be measured? Certainly I
can make any code fragile if I keep randomly changing the language
translator. So code using reduce is fragile if we remove reduce.
Similarly sum is fragile when we intend to remove that. Code is made
robust by using features that stay in the language. Keep reduce and
friends and make Python more robust.

>Alex
>

-- 
Robin Becker




More information about the Python-list mailing list