News for hackers. Stuff that matters.
Re:Simple apply/filter/reduce package in Go by metaphorm on Friday April 03, 2015 @09:24AM (#9315689)
filter and reduce are both builtins in Python and I see nothing discouraging anyone from taking full advantage of them.
Re:Simple apply/filter/reduce package in Go by svisser on Friday April 03, 2015 @09:29AM (#9315714)
In Python 3 reduce was removed and you'd have to use functools.reduce. Similarly lambda functions are a bit of a mistake, in Guido's opinion, as well as his preference to use list comprehensions over filter(). I don't expect to see more functional programming constructs anytime soon in Python. That being said, list comprehensions work quite well in Haskell, Python, etc.
Re:Simple apply/filter/reduce package in Go by kasabali on Friday April 03, 2015 @09:44AM (#9315801)
GvR discourages them if that's a strong enough reason for you :)
Re:Simple apply/filter/reduce package in Go by metaphorm on Friday April 03, 2015 @10:50AM (#9316176)
its not, actually. he seems to discourage them on the grounds that a list comprehension would be better. however, that's just alternate syntax for a logically equivalent operation. personally, I use whichever one is more clear to me based on context. I appreciate having the option. Maybe you say that's un-Pythonic because "there should be just one way to do things", but I'm not particularly dogmatic and not persuaded by that.
Re:Simple apply/filter/reduce package in Go by falcolas on Friday April 03, 2015 @11:06AM (#9316269)
List comprehension produces a different output than reduce (since reduce does not have to produce a list). Reduce and for loops are better compared.

For loops make the logic occurring on each operator explicit and in the current frame of reference, as opposed to reduce, which splits the logic from the point of operation.

Also, when reduce is used to produce an artifact similar to a list comprehension: the list comprehension is going to be better optimized, more comprehensible for many programmers, and with two character changes can be turned into a generator instead of a memory-heavy list.