List Comprehension Syntax
Eric S. Johansson
esj at harvee.org
Sat Jul 10 11:38:52 EDT 2004
Dave Brueck wrote:
> What I like about LCs is that they made sense to me before reading the
> documentation - they just came across as very expressive of what was
> happening. I use the simplest forms, i.e.
...
> throw away the resulting list).
good advice. Thank you for making this clear.
> I'm not so sure. Why program to the lowest common language denominator?
> I don't suggest going to the extreme to use obscure language quirks just
> because you can, but it doesn't make sense to avoid using a feature at
> your disposal because it's unique to a language (or, in this case, a
> small set of languages).
>
> Half the reason you use one language over another is because of the
> toolset it gives you. In the case of list comprehensions, they are
> usually chosen for the very reason that they *do* allow you to express a
> problem in natural terms.
it all depends on your definition of natural terms. ;-)
For me, the abstractions I use tend to be higher level than what most
languages support and is always a loss of clarity in the translation to
implementation. Python minimizes the translation distance for me.
Sometimes I find myself avoiding language quirks and features because
I'm trying to get a job done and I don't want to go through the mental
puzzle of mapping the abstract form into the implementation form using a
particular feature. So for example, I use for loops in preference to
list comprehensions just because it's faster to implement and get the
job done.
Most customers don't pay you for pretty code, they pay you to accomplish
something quickly and make it understandable to the less skilled people
following you. which probably explains why so much software is crap but
that's a whole different discussion.
your observation about reasons for choosing languages are certainly
accurate for most people but for me, it's quite different. If I can't
write code using speech recognition without doing a job on my throat, I
won't use the language. List comprehension syntax is approaching dammed
ugly for speech recognition users.
but thank you again for your clear example of how you use list
comprehensions.
---eric
More information about the Python-list
mailing list