Posted on May 31, 2007 at 7:36 pm

Whats wrong with reduce ?

Of late, Among the Python crowd, I’ve seen that people generally dispise using map, filter and reduce. A friend was reviewing my code the other day and he’s like surprised with the number of maps with lambdas spewed across. I was reading a post on John Resig’s blog and I saw some comments by someone. My contention is, whats wrong with using map, filter and reduce (and lots of lambdas) ? I dunno thats the way I code, My friend tried to tell me that its not a good practice and I talk about how I hate Bondage and Discipline. Ok, I agree that you can use list comprehensions or generator expressions to replace map and filter. But how can you simulate reduce without getting down to loops ? Ah yeah, maybe you can mess around using iterators and generators. But isn’t reduce simpler ? C’mon folks reduce (foldl, foldr) is not just for sum() and product(), there’s a lot more to it (refer: The mapreduce paper). Just because the BDFL doesn’t like it, doesn’t mean that we need to using it. We’ll think about it when Py3k comes out :)

Leave a Reply