<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, 10 May 2018 at 16:49, Ed Kellett <<a href="mailto:e%2Bpython-ideas@kellett.im">e+python-ideas@kellett.im</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2018-05-10 16:10, Guido van Rossum wrote:<br>
> Please no, it's not that easy. I can easily generate a stream of +1s or -1s<br>
> for any proposal. I'd need well-reasoned explanations and it would have to<br>
> come from people who are willing to spend significant time writing it up<br>
> eloquently. Nick has tried his best and failed to convince me. So the bar<br>
> is high.<br>
> <br>
> (Also note that most of the examples that have been brought up lately were<br>
> meant to illustrate the behavior in esoteric corner cases while I was<br>
> working out the fine details of the semantics. Users should use this<br>
> feature sparingly and stay very far away of those corner cases -- but they<br>
> have to be specified in order to be able to implement this thing.)<br>
<br>
Poor prospects, then, but I'll do my best.<br>
<br>
I think the most obvious argument (to me) favouring `given` over `:=` is<br>
that it separates the two things it's doing:<br>
<br>
if m.group(2) given m = pattern.search(data):<br>
<br>
as opposed to the more-nested := version:<br>
<br>
if (m := pattern.search(data)).group(2):<br>
<br>
which, at least to me, is more complicated to think about because it<br>
feels like it's making the .group() something to do with the assignment.<br>
<br>
Put another way, I think your use of parentheses when discussing the<br>
*pronunciation* of this thing is telling. It feels as though one needs<br>
to start in the middle and then go in both directions at once, first<br>
explaining the origin (or destination) of the operand in question in a<br>
parenthesized offshoot, and then switching context and describing what<br>
is done to it. It's midly mentally taxing. I'm sure we can all live with<br>
that, but I don't want to: Python's exceptionally-readable syntax is one<br>
of the bigger reasons I choose it.<br>
<br>
There's a striking parallel in C, where the well-known idiom:<br>
<br>
while ((c = getchar()) != EOF) ...<br>
<br>
has an obviously-nicer alternative:<br>
<br>
while (c = getchar(), c != EOF) ...<br>
<br>
Most people I show this to agree that it's nicer, despite the fact that<br>
it manages to repeat a variable name *and* use the comma operator. I<br>
don't have proof, but I'd suggest that unwrapping that layer of context<br>
for the reader imparts a significant benefit.<br>
<br>
The C example also provides a convenient test: if you think the former<br>
example is nicer, I can just give up now ;)<br></blockquote><div><br></div><div>IMHO, all these toy examples don't translate well to the real world because they tend to use very short variable names while in real world [good written code] tends to select longer more descriptive variable names.</div><div><br></div><div>Try replacing "c" with a longer name, like input_command, then it becomes:</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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"> while ((<span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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">input_command</span> = getchar()) != EOF) ...</span><br style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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"><br></div><div><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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"> while (<span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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">input_command</span> = getchar(), <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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">input_command</span> != EOF) ...</span><br style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;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"><br></div><div>In the second example, having to type the variable name twice is an annoyance that adds almost nothing to readability, so I would definitely prefer the first one.</div></div><div><br></div><div>The "given" proposals have the same issue. </div><div><br></div><div>(a shame we can't use "as", for reasons already stated, it would have been perfect otherwise)</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Gustavo J. A. M. Carneiro<div>Gambit Research<br>"The universe is always one step beyond logic." -- Frank Herbert</div></div></div></div>