> E.g. Python's list comprehensions are merely syntactic sugar for filter + map, but they make functional code so much more readable.
Can't say I agree. Maybe it's because I worked with simple functional programming primitives like filter and map before I ever really worked with Python, but I find Python list comprehensions weirder and harder to read than things like Clojure's thread macros, Ruby blocks, or even just chaining functional method calls together using the normal dot syntax in Java or Scala.
They do look better than the equivalents shown in the official Python documentation¹:
squares = list(map(lambda x: x**2, range(10)))
but that is exceptionally hideous and not what I'd consider a normal way to write functional code for dealing with collections or streams.
Seems like a Python workaround for a Python problem to me. ¯ \ _ ( ツ ) _ / ¯
For whatever reason, having just the global functions feels more natural to me in Lisps, but weirder where function names precede the opening parentheses.
I do also find the comprehensions more readable when one is actually using all of their components, i.e., when the function in the map behind the sugar would not be the identity function. But occasionally, when all the author really wanted to do is filter, you'll see stuff like
[x for x in ... if ...]
and that always strikes me as a bit weird and unfortunate.
> Also some historical context, Python's list comprehension are based on Haskell's
I didn't know that! I do kinda like Python's preference for English keywords over arrows here, even though the Haskell syntax is more concise or whatever.
Haskell always seemed like it was meant for the really mathematical subset of compsci that loves notation and that's why some of those who really love compsci love it.
Can't say I agree. Maybe it's because I worked with simple functional programming primitives like filter and map before I ever really worked with Python, but I find Python list comprehensions weirder and harder to read than things like Clojure's thread macros, Ruby blocks, or even just chaining functional method calls together using the normal dot syntax in Java or Scala.
They do look better than the equivalents shown in the official Python documentation¹:
but that is exceptionally hideous and not what I'd consider a normal way to write functional code for dealing with collections or streams.Seems like a Python workaround for a Python problem to me. ¯ \ _ ( ツ ) _ / ¯
--
1: https://docs.python.org/3/tutorial/datastructures.html