<div dir="ltr">I do think the pronunciation issue that Greg notices is important.  I teach Python for most of my living, and reading and discussing code segments is an important part of that.  When focussing on how Python actually *spells* something, you can't always jump to the higher-level meaning of a construct.  For some complex expression—whether or not "binding expressions" are added—sometimes it makes sense to give a characterization of the *meaning* of the expression, but other times you want to say aloud the entire spelling of the expression.<div><br></div><div>Although feelings are mixed about this, I like the "dunder" contraction for this purpose.  It's less of a mouthful to say "dunder-init" than "underscore-underscore-init-underscore-underscore" aloud.  And once you learn that shorthand, it's unambiguous.</div><div><br></div><div>I think I'd pronounce:</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;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">    if (diff := x - x_base) and (g := gcd(diff, n)) > 1:</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;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"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;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">        return g</span><br><div><br></div><div>As:</div><div><br></div><div>"If diff bound to x minus x_base (is non-zero), and g bound to gcd of diff comma n is greater than 1, return g"</div><div><br><div class="gmail_extra">But having a convention for pronouncing this would be nice, rather than it being my idiosyncrasy. </div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 23, 2018 at 8:23 PM, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[Tim]<br>
<span class="">>> if (diff := x - x_base) and (g := gcd(diff, n)) > 1:<br>
>>     return g<br>
<br>
</span>[Greg Ewing <<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>>]<br>
<span class="">> My problem with this is -- how do you read such code out loud?<br>
<br>
</span>In the message in which I first gave that example:<br>
<span class=""><br>
    if the diff isn't 0 and gcd(diff, n) > 1, return the gcd.<br>
   That's how I _thought_ of it from the start.<br>
<br>
</span>In my mind, `x - x_base` doesn't even exist except as a low-level<br>
definition of what "diff" means.  It's different for the other test:<br>
_there_ `g` doesn't exist except as a shorthand for "the gcd".  In one<br>
case it's the name that's important to me, and in the other case the<br>
expression.  The entire function from which this came is doing all<br>
arithmetic modulo `n`, so `n` isn't in my mind either - it's a<br>
ubiquitous part of the background in this specific function.<br>
<br>
But you did ask how_I_ would read that code ;-)  Anyone else is free<br>
to read it however they like.  I naturally read it in the way that<br>
makes most sense to me in its context.<br>
<span class=""><br>
<br>
> From my Pascal days I'm used to reading ":=" as "becomes". So<br>
> this says:<br>
><br>
>    "If diff becomes x - base and g becomes gcd(diff, n) is<br>
>     greater than or equal to 1 then return g."<br>
><br>
> But "diff becomes x - base" is not what we're testing!<br>
<br>
</span>I don't really follow that.  In Python,<br>
<br>
    if f() and g > 1:<br>
<br>
first tests whether `f()` "is truthy", regardless of whether it does<br>
or doesn't appear in a binding expression.  Because this code is<br>
working with integers, there's an _implied_ "!= 0" comparison.<br>
<span class=""><br>
<br>
> That makes it sound like the result of x - base may or may not<br>
> get assigned to diff, which is not what's happening at all.<br>
<br>
</span>Then I suggest the problem you're having doesn't stem from the binding<br>
expression, but from that you're omitting to fill in the != 0 part:<br>
if you're not thrown by "greater than 1", I can't see how you can be<br>
thrown by "not zero".<br>
<span class=""><br>
<br>
> The "as" variant makes more sense when you read it as an<br>
> English sentence:<br>
><br>
>    if ((x - x_base) as diff) and ...<br>
><br>
>    "If x - x_base (and by the way, I'm going to call that<br>
>     diff so I can refer to it later) is not zero ..."<br>
<br>
</span>So read the original as "if diff (which is x - x_base) is not zero ...".<br>
<br>
Regardless, Guido has already said "as" is DOA (Dead On Arrival)<br>
(illustrating that it's also common enough in English to give a short<br>
name before its long-winded meaning ;-) ).<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/mertz%40gnosis.cx" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>mertz%40gnosis.cx</a><br>
</div></div></blockquote></div><br><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></div></div>