[Python-ideas] if-syntax for regular for-loops

Vitor Bosshard algorias at yahoo.com
Sat Oct 4 01:42:23 CEST 2008

> On Fri, Oct 3, 2008 at 12:33 PM, Andreas Nilsson wrote:
> > Thanks for the pointer!
> > I don't buy the argument that newlines automagically improves readability
> > though. You also get increased nesting suggesting something interesting is
> > happening where it isn't and that hurts readability.
> > And as Vitor said, all other constructions of the form 'for i in items' can
> > have if-conditions attached to them, it's really not that far-fetched to
> > assume that the loop behaves the same way. Consistency good, surprises bad.
> Yeah, I know what you mean, and I kind of liked the idea of adding the
> if statement to the for loop (for consistency, if nothing else), but
> it's been discussed before, and plenty of people have made the same
> argument.  Probably not worth it.

Besides consistency I think the one major benefit to for..if
loops is that often you don't just save a line, but also an indentation
level (whenever you use the if clause solely as a filter), which
actually increases readability, specially when whatever you do within
the loop is
relatively long, with its own indentations.

The syntax just feels natural. For example:

for i in somelist if i.pending:
    <do stuff> 

I really don't see any disadvantage here.

PS: moving the discussion from python-dev to python-ideas.

¡Todo sobre Amor y Sexo!
La guía completa para tu vida en Mujer de Hoy.                       

More information about the Python-ideas mailing list