Re:The fate of reduce() in Python 3000 (2005)
by wodenokoto on Tuesday January 01, 2019 @09:43AM
(#18800351)
Why were map and filter kept? What can you do that cannot be as easily done with generator expressions?
[ Parent
| on HN ]
Re:The fate of reduce() in Python 3000 (2005)
by duckerude on Tuesday January 01, 2019 @10:19AM
(#18800477)
I'm sometimes tempted to use it in loops, when
for x in map(func, iterable):
...
is cleaner than for x in (func(y) for y in iterable):
...
and shorter than for y in iterable:
x = func(y)
...
But that mostly only makes sense if you already have a suitable named function (e.g. str), and I usually end up going with the third variant anyway.There's an analogous case with filter and `if not cond: continue`.
map and filter calls are trivially rewritten to generator expressions, but it's not necessarily an improvement.
Re:The fate of reduce() in Python 3000 (2005)
by studentik on Tuesday January 01, 2019 @09:56AM
(#18800397)
Coconut has many examples of functional programming techniques that cannot be easily done with python: https://coconut.readthedocs.io/en/master/DOCS.html
Strangely FP is not popular among python developers.
Re:The fate of reduce() in Python 3000 (2005)
by danharaj on Tuesday January 01, 2019 @10:36AM
(#18800531)
It's a pain in the ass to write functional code in python because the syntax is not optimized for it. A functional programming language makes lambda and (partial) application as cheap as possible, which Python does not.
Re:The fate of reduce() in Python 3000 (2005)
by AlexCoventry on Tuesday January 01, 2019 @02:59PM
(#18801945)
I think you can get 95% of the benefit of FP just by favoring abstractions which present a functional interface. Python hasn't really gotten in my way, in that respect, though it would be nice to have first-class persistent data structures with structural sharing.
Re:The fate of reduce() in Python 3000 (2005)
by mlevental on Tuesday January 01, 2019 @02:23PM
(#18801749)
is coconut used in production? seems like a really bad idea?
Re:The fate of reduce() in Python 3000 (2005)
by studentik on Tuesday January 01, 2019 @08:13PM
(#18803493)
It's python after all, so why not?
Re:The fate of reduce() in Python 3000 (2005)
by masklinn on Tuesday January 01, 2019 @02:51PM
(#18801880)
> What can you do that cannot be as easily done with generator expressions?
Technically nothing, but at the same time if you already have a function (especially a builtin) map/filter is more convenient and can be faster. And they're first-class objects which comprehensions are not, which can be convenient.
The goal is not necessarily to prune all redundancies: reduce already existed when sum/min/max/any/all were added, despite the latter being fairly simple special cases of the former (not quite entirely for min/max, but not far).
Re:The fate of reduce() in Python 3000 (2005)
by InclinedPlane on Tuesday January 01, 2019 @07:23PM
(#18803306)
Why bother having any control logic other than conditionals and gotos? Because they signal intent directly.