[Python-ideas] Assignments in list/generator expressions
ncoghlan at gmail.com
Sun Apr 10 17:29:52 CEST 2011
On Mon, Apr 11, 2011 at 1:13 AM, Laura Creighton <lac at openend.se> wrote:
> Comments like this make me wonder if the problem is that those people
> actually find those constructs more readable. If we largely cannot
> agree on what makes for more readable code, then I think we have a
> different problem than the one I thought we had (people showing off
> their knowledge of how to use every new feature).
I don't think it's an either/or problem - I think both of those things
can cause problems with code readability.
One of the first questions I want to ask people that try to push
Python's comprehension syntax to (and past) its limits is whether they
have come to Python programming from a mathematics or pure functional
programming background. If they have, then "normal" imperative
programming will feel understandably unnatural to them, despite it
being the idiomatic approach to Python programming (with
comprehensions only being employed for those relatively simple cases
they were really designed to handle).
But I also see people using metaclasses for things that should be
decorators, context managers for things that should be ordinary higher
order functions, higher order functions for things that should just be
plain boring old functions, closures for things that should be
classes... all of those I tend to chalk up to "when you have just
discovered a nice shiny new hammer, everything looks like a nail (even
when you still have the saw, screwdriver and pliers in the toolkit)".
Or, as I once heard it put, some code overuses powerful constructs to
the point where it is like "using a bazooka to kill a fly" :)
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas