<div dir="ltr">Even though I really don't want new null-coalescing operators, I really appreciate the ternary operator in Python (or in C).<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 2, 2016 at 12:38 PM, Mikhail V <span dir="ltr"><<a href="mailto:mikhailwas@gmail.com" target="_blank">mikhailwas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">result = a > b ? x : y<br>
<br>
is IMHO a syntactical herecy. Such things disgust me from programming.<br>
Why on earth one cannot just wrap it in function<br>c = nicefunc(a,b)<br></blockquote><div><br></div><div>The problem here is that the general form isn't ONLY to return 'x' or 'y' but the decide between arbitrary values. Hard-coding the variables into the function loses 90%+ of the point.</div><div><br></div><div>So the general function would need a signature like:</div><div><br></div><div> c = nicefunc(a, b, x, y)</div><div><br></div><div>The problem here is that this call might be:</div><div><br></div><div> c = nicefunc(a, b, run_for_hours(), has_side_effects())</div><div><br></div><div>We only want ONE of 'x' and 'y' to eagerly evaluate. In the C or Python ternary we get exactly that. Obviously, that also happens in your fully spelled out if/else block too, but that's multiline and needs to setup variables not just be used as an expression.</div></div><br clear="all"><div><br></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>