<p dir="ltr">In my mind, these proposed complications of the 'for' loop would *introduce* inconsistency, NOT reduce it.</p>
<p dir="ltr">It's simple to remember that suites nest statements while comprehensions are expressions on single (logical) lines. Adding more edge cases to blue the distinction makes cognitive load higher.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Oct 3, 2016 9:38 PM, "Ken Kundert" <<a href="mailto:python-ideas@shalmirane.com">python-ideas@shalmirane.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In my experience it is exceptions and inconsistencies that consume 'working<br>
memory in the brain of humans'. By eliminating the distinction between list<br>
comprehensions and for loops we would be making the language simpler by<br>
eliminating an inconsistency.<br>
<br>
Furthermore, I do not believe it is valid to discard a potentially good idea<br>
simply because if taken to extreme it might result in ugly code. With that<br>
justification one could reject most ideas. The fact is, that in many cases this<br>
idea would result in cleaner, more compact code. We should be content to offer<br>
a language in which it is possible to express complex ideas cleanly and simply,<br>
and trust our users to use the language appropriately.<br>
<br>
For example, it was suggested that one could simplify a multi-level loop by<br>
moving the multiple levels of for loop into a separate function that acts as<br>
generator. And that is a nice idea, but when writing it, the writing of the<br>
generator function represents a speed bump. Whereas writing something like the<br>
following is simple, compact, quick, and obvious. There is no reason why it<br>
should not be allowed even though it might not always be the best approach to<br>
use:<br>
<br>
  Â  for i in range(5) for j in range(5) for k in range(5):<br>
  Â  Â  Â  ...<br>
<br>
And I would really like to be able to write loops of the form:<br>
<br>
  Â  for item in items if item is not None:<br>
  Â  Â  Â ...<br>
<br>
It is something I do all the time, and it would be nice if it did not consume<br>
two levels on indentation.<br>
<br>
-Ken<br>
<br>
On Tue, Oct 04, 2016 at 01:31:22PM +1000, Nick Coghlan wrote:<br>
> On 4 October 2016 at 08:18, Erik <<a href="mailto:python@lucidity.plus.com">python@lucidity.plus.com</a>> wrote:<br>
> > The expression suggested could be spelled:<br>
> ><br>
> > for i in range(10): if i != 5:<br>
> >  Â  Â body<br>
> ><br>
> > So, if a colon followed by another suite is equivalent to the same construct<br>
> > but without the INDENT (and then the corresponding DEDENT unwinds up to the<br>
> > point of the first keyword) then we get something that's pretty much as<br>
> > succinct as Dominik suggested.<br>
><br>
> What's the pay-off though? The ultimate problem with deeply nested<br>
> code isn't the amount of vertical whitespace it takes up - it's the<br>
> amount of working memory it requires in the brain of a human trying to<br>
> read it. "This requires a lot of lines and a lot of indentation" is<br>
> just an affordance at time of writing that reminds the code author of<br>
> the future readability problem they're creating for themselves.<br>
><br>
> Extracting named chunks solves the underlying readability problem by<br>
> reducing the working memory demand in reading the code (assuming the<br>
> chunks are well named, so the reader can either make a useful guess<br>
> about the purpose of the extracted piece without even looking at its<br>
> documentation, or at least remember what it does after looking it up<br>
> the first time they encounter it).<br>
><br>
> By contrast, eliminating the vertical whitespace without actually<br>
> reducing the level of nesting is merely hiding the readability problem<br>
> without actually addressing it.<br>
><br>
> Cheers,<br>
> Nick.<br>
><br>
> --<br>
> Nick Coghlan  Â |  Â <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>  Â |  Â Brisbane, Australia<br>
> ______________________________<wbr>_________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div></div>