[Python-ideas] if-statement in for-loop

Steven D'Aprano steve at pearwood.info
Wed Oct 5 07:19:11 EDT 2016


On Tue, Oct 04, 2016 at 09:09:40PM -0700, Ken Kundert wrote:
> On Wed, Oct 05, 2016 at 03:07:42AM +1100, Steven D'Aprano wrote:
> > 
> > Extra newlines are cheap. Writing
> > 
> 
> The cost is paid in newlines *and* extra levels of indentation.

You've quoted me out of context -- I did also refer to extra indentation 
being cheap. At the point that it isn't any more, it is a code smell and 
you (that's generic you, not just you personally) should think hard 
about how the design of your code.


> Why isn't it the programmer that is writing the code the best person to decide 
> what is best?

Have you *seen* the quality of code written by the average coder?

And remember, fifty percent of coders are worse than that.

I jest, but only a bit.

For better or worse, of course every programmer can set their own style, 
within the constraints of the language. If they cannot bear the language 
contraints, they're free to use a different language, or design their 
own. Anyone can be "the best person to decide" for their own private 
language.

All languages have their own style, of what is or isn't allowed, what's 
encouraged and what's discouraged, and their own idiomatic way of doing 
things. The syntax constraints of the language depend on the language 
designer, not the programmers who use it. For some languages, those 
constraints are set by those who are appointed to sit on a standards 
board, usually driven by the corporations with the deepest pockets.
Python, it is Guido and the core developers who set the boundaries of 
what coding styles can work in Python, and while the community can 
influence that, it doesn't control it. It isn't a wild free-for-all 
where every programmer is "the best person to decide".

Some people might think that moving closer towards a Perl-ish one-liner 
culture by allowing (say):

    for x in seq for y in items if cond:
        block

makes Python better ("saves some lines! saves some indents!"), but to 
those who like the discipline and structure of Python's existing loop 
syntax, this will make Python significantly worse. No decision can 
please everybody.


-- 
Steve


More information about the Python-ideas mailing list