<div dir="ltr">Let me preface this by saying: I've already addressed the possibility of a form that tells you up-front that it's a function<br>Granted it was 8 replies ago and at the end of a long-winded response, so I'll summarize here:<br><br>A format like <PREFIX><EXPRESSION>[<SEPARATOR><SIGNATURE>] would, in my view, be preferable to a format that puts the signature first.<br>An example might be:<br><br>hand = sorted(cards, by=def card.suit with card)<br>hand = sorted(cards, by=return card.suit from card)<br>hand = sorted(cards, by=(:card.suit with card))  # the happiest form!<div>hand = sorted(cards, by==>card.suit :: card)  # eh...<br>etc...<br><br>There are many possibilities.<br><br>[MRAB]<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You're complaining that it's "noise", but I think you need a bit of <br>noise to tell you that it's defining a function</blockquote><div><br>I feel like the pseudo code example shows that at least isn't *always* true. Yes, the noise is neccessary for the<br>computer's sake, but it doesn't have to go in-front of the logic. It's usually not that important for the reader.<br>The intent is to sort cards by suit, not to declare a function that gets the suit of a card. The fact that you have<br>to declare a function is secondary to the intent.<br><br>If it were up to me, I'd make "by" the keyword for a key-function in sorted, sort, min, max, etc.</div><div>and have special secondary keywords for simple, common cases:<br><br><font face="monospace, monospace">>>> hand = sorted(cards, by_attr="suit")<br>>>> exam_grades.sort(by_item=-1)<br>etc...</font><br><br>[MRAB]<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">otherwise you'll see an expression and think it's evaluated immediately, but then you'll see the <br>"with" at the end telling you "oh, by the way, this is a function, so don't evaluate it now".</blockquote></div><br>That's true of most expressions:<br><br><font face="monospace, monospace">>>> grades = {"Sally": 92, "Jimmy": 83, "Beth": 87, "Alex": 98}<br>>>> best_student = max(grades, key=grades.get)<br>>>> print(best_student)</font><br>'Alex'<br><br>Assuming you know that grades.get is a method, you don't know that the expression passed to 'key'<br>is a function until you read the whole expression. If you don't know what grades.get is, you don't know<br>what kind of object is being passed to key:<br><br><font face="monospace, monospace">>>> best_student = max(spam, key=spam.eggs)</font><br><br>Is it catastrophic that you don't know what ham.eggs is?<br>Is it something to do with <font face="monospace, monospace">card.suit with card </font><font face="arial, helvetica, sans-serif">being a literal that<br></font>makes you demand to know what type of thing is being passed before you finish reading the expression?<br>Because that clearly isn't true in the case of variables.<br><br>Besides; you usually have several context clues leading up to the 'with' :<br><br>1) The function (if you're familiar with it)<br><br>2) The name of the function (if it's well named and you are familiar with the name)<br>e.g. add_callback, add_handler, on_mouseover, etc..<br><br>3) The name of a keyword parameter (if it's well named and you're familiar with the name)<br>e.g. key, callback, handler, event_handler, filter, etc...<br><br>4) The usage of a variable that has yet to be declared (just like in generator/comprehension expressions)<br>example:<br><br><font face="monospace, monospace">def best_hand(cards):<br>    hand = sorted(cards, key=card.suit with card)<br>    ...</font><br><br>My hunch is that the vast majority of cases satisfy enough of those that reading a 'with' would rarely be all that surprising.<br>I also assert that some of those conditions are far more critical to comprehending code, so if they're missing, your comprehension<br>ends long before you're "surprised" by the appearance of a 'with'.<br>All of the arguments in the following are clearly declared literals:<br><br><font face="monospace, monospace">foo = bar.baz(100, True, ham="spam")</font><br><br>Can you read that? In a sense, yes. Can you comprehend it? No! What if I asked you "where's the bug?".<br>Nope.<br><br>Another example (from D'Aprano):<br><br><font face="monospace, monospace">sm = difflib.SequenceMatcher(isjunk=True)<br>t = threading.Thread(target="hello")</font><br><br>Now imagine that none of the 4 context clues above are true. Can you read those? Can you see the bugs? Is there even a point to reading beyond where your comprehension stops?<br>If you don't know anything about what's expected for "target" or "isjunk" than reading any further isn't helpful.<br>Knowing that "hello" is a string right away saves you no pain. The paramount problem is that you don't know that it's supposed to be a function. You need to stop when you loose comprehension and read the docs. Then when you come back, you'll know that 'isjunk' should be a function.<br>The counter that there may be cases where none of the 4 context clues above exist indicates a more urgent problem than knowing the types of literals being passed (immediately or otherwise).<br><br>Also, by the time you hit the "with" it's not like the "new information" requires you to look back and re-examine anything. It's just new information like any other compound statement:<br><br><font face="monospace, monospace">>>> spam.eggs(ham)[parrot] <br># it's the value of 'spam'...<br># or rather the attribute 'eggs' of 'spam'...<br># or rather the result of calling the method 'eggs' of 'spam' with 'ham'...<br># or rather it's the 'parrot'th item of the result of calling the method 'eggs' of 'spam' with 'ham'</font><br><br>[MRAB]<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You gave an example in JavaScript and said that students had "very <br>little trouble" with it, but notice how the function itself began with a <br>reserved word.<br>If you're complaining about the word "lambda", that's fine,</blockquote><br>Yes, that was the context of the discussion I was referencing. Just the word "lambda".<br>In this ongoing discussion I've declared on two separate gripes: 1) the word itself and 2) the format.<br><br>I think a different format opens up other possible word choices, but that's not really important.<br><br></div></div>