On Mon, Feb 15, 2021 at 12:30 PM Guido van Rossum <gu...@python.org> wrote:

> On Mon, Feb 15, 2021 at 9:02 AM Ricky Teachey <ri...@teachey.org> wrote:
>
>> [...]
>> But if we could expand the  proposal to allow both anonymous and named
>> functions, that would seem like a fantastic idea to me.
>>
>> Anonymous function syntax:
>>
>> (x,y)->x+y
>>
>> Named function syntax:
>>
>> f(x,y)->x+y
>>
>
> Proposals like this always baffle me. Python already has both anonymous
> and named functions. They are spelled with 'lambda' and 'def',
> respectively. What good would it do us to create an alternate spelling for
> 'def'?
>

Thanks for responding. I don't want to derail this discussion especially
since I've brought it up in the last several months and didn't get anywhere
on it.

To answer the question though: I think it would really open up python to a
whole group of people are find the idea of "programming" too intimidating
but could benefit from it immensely. This could happen if writing a
function was made more similar to what they already KNOW how to write
(handwritten math).

A common thing I hear from colleagues is "I'm not a developer, I'm not a
programmer, I'm an engineer", and seeing this just intimidates people:

lambda x,y: (x**2+y**2)**0.5

def  hypotenuse(x,y):
    (x**2+y**2)**0.5

Allowing short one-line functions to be spelled something like this would
be more friendly because it looks so familiar, nearly identical to a
handwritten mathematical equation:

hypotenuse(x,y) => (x**2+y**2)**0.5

Anyway I've offered up this desire to this list before and for the most
part people haven't been very receptive, so I won't belabor it. But I
thought I'd bring it up again in this context since this:

f(x,y) => x+y

...and this:

(x,y) => x+y

...would be SO CLOSE to each other.

You could also write this, I suppose:

hypotenuse = (x,y) => (x**2+y**2)**0.5

But that isn't any better for the casually programming engineer than lambda
or def, to be honest.

On Mon, Feb 15, 2021 at 12:40 PM Jonathan Goble <jcgob...@gmail.com> wrote:

> On Mon, Feb 15, 2021 at 12:29 PM Ricky Teachey <ri...@teachey.org> wrote:
>
>> f(x,y)=>x+y->str
>>
>
> I can't -1 this enough. How do I read this?
>
> Imagine you have never seen this discussion and you come across this code
> in the wild. You are familiar with type hints, including return type
> annotations, but aren't familiar with this syntax. From that perspective,
> what does this code mean?
>
> ...
>
> My preferred spelling of the above (with the addition of sample parameter
> type hints) would be:
>
> f(x: int, y: int) -> str: x, y
>
> ...
>
> Even with that spelling, I'm -0.5 on the named function version (for the
> reasons described by Guido), and only +0.5 on the anonymous version
> (because I'm not convinced that it's needed).
>

I see your point and I would be fine with that spelling. With no type hints
it would look like:

hypotenuse(x,y): (x**2+y**2)**0.5

That would seem fine to me.

Anyway as I said above, I know this is an uphill battle. I'll leave it
alone unless other people come out liking the anonymous and non-anonymous
function syntax idea.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/UGBETLVFKZKYXKN3OP75A2ECEYI6Y6HP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to