Re:Javascript Arrays and Functional Programming
by nerdponx on Thursday August 03, 2017 @08:48AM
(#14919047)
JavaScript has an advantage on Python in this style, because Python lambdas are hideously ugly and JS anonymous functions are less hideously ugly. In Python it tends to be cleaner (and sometimes faster) to write list comprehensions instead of map() and filter(), especially since Python also has lazy generator comprehensions.
[ Parent
| on HN ]
Re:Javascript Arrays and Functional Programming
by pryelluw on Thursday August 03, 2017 @09:52AM
(#14919543)
Python actually discourages using map anf filter. Which is kind of weird to me but whatever.
Re:Javascript Arrays and Functional Programming
by nerdponx on Thursday August 03, 2017 @01:31PM
(#14921680)
Well in some cases it really is more efficient.
[func(x) if x in collection if cond(x)]
makes a single pass over the data and gives you a list, but list(map(func, filter(cond, collection)))
makes two passes and requires some extra function calls.I think the real reason is perceived legibility on the part of the Python core devs. I seem to recall a document from a while ago in which GvR himself came out in favor of list comprehension style. "Explicit is better than implicit".