<div dir="ltr"><span style="text-decoration-style:initial;text-decoration-color:initial;font-size:12.8px;float:none;display:inline">[Chris Angelico]<br></span><blockquote class="gmail_quote" style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">That right there is unacceptable. You should not have to know the<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">destination to understand what something fundamentally is.</span></blockquote><span style="text-decoration-style:initial;text-decoration-color:initial;font-size:12.8px;float:none;display:inline"><br>You don't *have* to know what the parameter "key" is to know that (value[card.suit] ... with card) is a function. You can identify that it's a function just by reading the full expression. However, if you don't know what "key" is, then it'll cause far more confusion than the late declaration of the function's parameters.<br><br><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[Chris Angelico]<br></span></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="text-decoration-style:initial;text-decoration-color:initial;font-size:12.8px;float:none;display:inline">You can't </span><span style="text-decoration-style:initial;text-decoration-color:initial;font-size:12.8px;float:none;display:inline">redefine language syntax based on the function being called.</span></blockquote><div><br>That's not at all what I suggested. You were walking through my example from the reader's perspective. I was explaining how the reader will often have plenty of context about what they're reading before they get to the signature declaration. Whether it be because they know what the "key" parameter means or because they know "card" is undeclared or both. I never claimed the language syntax should be based on the function being called.<br><br>func = value[card.suit] if card not in wilds else wild_value with card<br><br>Works independent of the function being called. It's just not a common use case because it obviates the expressiveness of anonymous functions. You might as well use a "def" statement.<br><br>The thing that makes callbacks difficult is not knowing how they're called. I tried to throw a little JavaScript into my curriculum once thinking "how bad can it be?" and suggested my students work on a project using the <a href="https://bl.ocks.org/mbostock/1062288">Force Directed Graph from D3.js</a>. That was a HUGE mistake not because anonymous functions are confusing but because the example (at the time) had no documentation at all <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">(</span><a href="https://bl.ocks.org/mbostock/4062045" style="color:rgb(17,85,204);font-size:small;background-color:rgb(255,255,255)">like this one</a><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">) </span>and used mysterious callbacks everywhere. The main documentation for D3.js is super difficult to navigate, when all you want to do is slightly modify one of the examples (use svg images for the nodes and have stats display "on mouse over").<br><br>If you don't know what <font face="monospace, monospace">"".join()</font> does, then you're going to have trouble making sense of:<br><br><font face="monospace, monospace">def initials(person):<br>     return "".join(name[0] + "." for name in person.names if name)</font><br><br>The late assignment of the name variable will NOT be your main source of confusion. If you do know what <font face="monospace, monospace">"".join() </font><font face="arial, helvetica, sans-serif">does, then it should take you much less context to realize you're reading a generator expression. By the time you read the yet-to-be-assigned <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">"name"<span> </span></span>variable you should be tipped off.</font><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 21, 2018 at 1:58 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, Aug 22, 2018 at 4:56 AM, Abe Dillon <<a href="mailto:abedillon@gmail.com">abedillon@gmail.com</a>> wrote:<br>
> [Chris Angelico]<br>
>><br>
>> Okay, let's read that.<br>
>> hand = # we're assigning this to the name 'hand'<br>
>> sorted( # calling the function named 'sorted'<br>
>> cards, # positional argument, whatever's in the 'cards' variable<br>
>> by= # keyword argument, what comes next is the 'by' argument<br>
>> value[card.suit] # subscript 'value' with 'card.suit'<br>
>> if card is not wild # yep<br>
>> else max_value # so we have an alternative<br>
>> with card # WAIT WAIT WAIT<br>
>> Once you get to 'with card', you have to go back and completely<br>
>> reinterpret everything prior to that as a function.<br>
><br>
><br>
> The revelation that it's a function should come when you read the "by" or<br>
> "key". If you don't know what that parameter is, then that's where the "wait<br>
> wait wiat!" should happen.<br>
<br>
</span>That right there is unacceptable. You should not have to know the<br>
destination to understand what something fundamentally is. You can't<br>
redefine language syntax based on the function being called.<br>
<div class="HOEnZb"><div class="h5"><br>
ChrisA<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>
</div></div></blockquote></div><br></div>