126 points · by BiteCode_dev · 3y ago · 17 comments
Last but not least, since it removes the additional frame that the comprensions used be wrapped in, it will fix the way you interact with them using pdb, which has always been rough thanks to this invisible indirection layer.
I assume JIT will also appreciate the change, so let's see if pypy moves on this.
Migrating to a PEG parser opened so many opportunities for Python. I never expected we would see so many good things come out of it, after years of defending LL1 to keep the reference implementation simple. E.G: the new error messages are awesome.
As someone coming from Haskell I find it odd that comprehensions are prioritized over generic maps (fmaps) and traversals in Python. Not only they are more verbose syntax-wise and don't allow for partial application, they also discourage people from discovering generators, as most of the tutorials go with [] and {} brackets instead of the lazy (). At least with map() people could get acquainted with generators earlier.
> I assume JIT will also appreciate the change, so let's see if pypy moves on this.
I wonder if there's a real difference between map and comprehensions performance when it comes to JIT inlining.
The argument is that making it hard to use higher-order functions discourages point-free style. "Explicit is better than implicit" is a design principle of the language.
It's pretty explicit. Nothing is implied, it only can work one way.
Unfortunately, partial application doesn't work in Python, the same way it works in Haskell. If a function has 3 args, calling `f(x)` is a guaranteed runtime `TypeError`. There is functools.partial to hack it into the language for cases where you absolutely need it but overall it's bad developer experience. In fact, when I do need to partially apply `f(x, y, z)` I much prefer doing `g = lambda y, z: f(fixed_x, y, z)` because it's clearer than using functools.partial.
You can also refactor partial function applications into callable classes depending on your needs, which is basically what `functools.partial` does internally anyway.
If you think in terms of an expression language that composes functions, then map and filter are more natural.
If you think in terms of a statement language with special syntax for computation expressions, then comprehensions are more natural.
Even in Racket (a scheme), idiomatic code seems to prefer the `for/thing` family of macros, which have a variety of flavors and keyword arguments to support map, filter, reduce, mapcar, etc.
Whatever floats your boat.