<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 27, 2018 at 11:46 PM, Matt Arcidy <span dir="ltr"><<a href="mailto:marcidy@gmail.com" target="_blank">marcidy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto">From readability, the examples put forth have been to explain the advantage, with which I agree. However, i do not believe this scales well.</div><div dir="auto"><br></div><div dir="auto">[(foo(x,y) as g)*(bar(y) as i) + g*foo(x,a) +baz(g,i) for x... for y...]</div></div></blockquote><div><br></div><div>This definitely looks hard to read. Let's compare it to:</div><div><br></div><div>lst = []</div><div><font face="monospace, monospace">for x in something:</font></div><div><font face="monospace, monospace"> for y in other_thing:</font></div><div><span style="font-family:monospace,monospace"> g = f(x, y)</span><br></div><div><font face="monospace, monospace"> i = bar(y)</font></div><div><font face="monospace, monospace"> lst.append(g*foo(x,a) + baz(g,i))</font></div><div><font face="monospace, monospace"><br></font></div><div>Obviously the one-liner is shorter, but the full loop looks a heck of a lot more readable to me.</div><div><br></div><div>I was thinking of an example closer to the PEP like this:</div><div><br></div><div><font face="monospace, monospace">[((my_object.calculate_the_quantity(quant1, vect2, arr3) as x), log(x)) for quant1 in quants]</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">Just one "as" clause, but a long enough expression I wouldn't want to repeat it. I still feel this suffers in readability compared to the existing option of (even as a non-unrolled comprehension):</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="monospace, monospace">[(x, log(x)) for x in (<span style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">my_object.calculate_the_quantity(quant1, vect2, arr3) <span style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">for quant1 in quants)]</span></span></font></div><div><br></div><div><br></div><div>Sure, again we save a couple characters under the PEP, but readability feels harmed not helped. And most likely this is another thing better spelled as a regular loop.</div><div> </div></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>