I was quite feeling pretty positive about the 'stab' (thanks Steve for this term!) operator idea, until I tried out some examples locally, and it just feels a bit too out-of-place in python, for me (100% subjective opinion here).

Having used stabs and compact closure syntax in various languages: swift, c++, javascript, I'd assumed that the joy of just writing `c=>c.foo()` would translate well to python (sometimes lambda x: x.foo() just seems too cumbersome to write out, even if this is a lazy feeling, it's real).
But, despite trying a few variants:  ->, =>, different whitespace, etc.. , they all still felt non-ideal.

I think the main difference, for me, is that the other languages that have adoped this syntax all rely much more on symbols (non-textual tokens) for control flow and structure.  (braces, ternary operators, block syntax, etc..) so adding in another non-textual token that also has structural meaning feels natural.  You're already 'reading' the symbols to understand what the language is doing, so there are no big surprises when stabs come along.

With python there are very few (any?) purely symbolic control flow tokens, and so I naturally expect words to be present to indicate what's going on.  Suddenly there's a symbol that indicates a new control structure, and it risks getting lost in the noise.

On balance, I'd probably end up using stabs if they were added to Python, but having tried out a few examples on existing code, no longer think it's worth adding them.

Thanks

Steve

On Tue, Feb 23, 2021 at 1:01 PM Paul Sokolovsky <pmiscml@gmail.com> wrote:
Hello,

On Tue, 23 Feb 2021 23:29:33 +1100
Steven D'Aprano <steve@pearwood.info> wrote:

> On Tue, Feb 23, 2021 at 11:27:12AM +0100, Stéfane Fermigier wrote:
>
> > Also: I know there are several modern computer languages that use
> > arrows to represent anonymous functions (JS, Kotlin, Scala...). 
>
> Javascript: first release was 1995, making it 25 years old. It's
> older than most Javascript programmers.
>
> Kotlin is only 9 years old. But Scala is 17 years old.
>
> (By the way, Julia calls the -> arrow "the stab operator". I think
> that's amusing.)
>
> Python has a long history of taking inspiration from other languages,
> but we've had anonymous functions for longer than Javascript has
> existed. This proposed arrow function would just be an alternative
> spelling for the same thing. It adds no more power, and no more
> expressiveness to the language.
>
> It would be just one more thing to learn, one more decision to make
> ("lambda or arrow?"), one more question to be asked a thousand times
> ("what's the difference between lambda and arrow?").

So, (unlike JS) we should make sure that there's no (semantic)
difference between lambda and arrow functions, and the answer to
"which?" should be "what you want or whatever your boss says".

(Btw, syntactically, there may be difference. I hope that we'll
eventually extend lambda to multiline, I'm not so sure about arrow. Of
course, with braces syntax variant both will be multiline).

[]

--
Best regards,
 Paul                          mailto:pmiscml@gmail.com
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QKPHHKETF2RYDCPTT3C5PKLUB5IDQJIP/
Code of Conduct: http://python.org/psf/codeofconduct/