Attitude about new keywords

Dave Brueck dave at pythonapocrypha.com
Mon Feb 10 13:55:07 EST 2003


On Mon, 10 Feb 2003, Michele Simionato wrote:

> I guess this is subjective, I am not bothered at all by the reverse
> order in list comprehensions
>
> [x for x in range(10) if x!=5]
>
> which I find very readable.

Me too. I think the key to its readability is that it is enclosed in
brackets, so I wouldn't mind if the new expression required parentheses
around it (I wouldn't mind because I'd probably enclose if-expressions in
parens anyway, required or not).

People tend to read code in groups of tokens, whole lines, or even entire
blocks, and not individual keywords, so the demand for "pure" LtoR or RtoL
reading doesn't sway me much - your brain recognizes patterns of keywords.
It is completely analagous to reading prose - only a beginning reader
actually interprets words (or even letters) one at a time; instead, whole
phrases are recognized as single entities.

Unreadable code is often code that's written in such a way that it doesn't
jump out to you as any easily-recognized pattern. After trying out the
PEP syntax even just a little, lines of code with the pattern:

w = (x if y else z)

seem to "scan" well, have clear meaning, and aren't at all confusable with
if _statements_.

> I am becoming quite pessimistic that we will ever reach a consensus...

Me too!

-Dave





More information about the Python-list mailing list