On Wed, Oct 27, 2021 at 5:14 PM Brendan Barnwell <brenb...@brenbarn.net> wrote:
>         Now it's true that we have asymmetry, in that SIMPLE logic can be
> readably inlined as an early-bound default, whereas even simple logic
> cannot be inlined as a late-bound default because there is no inline way
> to express late-bound defaults.  But I still think it's worth noticing
> that the new syntax is not going to add a "full dimension".  It is only
> going to be useful for VERY SIMPLE late-bound default values.  If the
> late-bound default is too complicated, inlining it will backfire and
> make things LESS readable.  So although the syntax is orthogonal, it is
> not really separating out early and late default binding; it is only
> separating "simple late default binding".

And that right there is the crux of it. The simple cases ARE quite
common. Of course there will always be cases that don't work that way,
so yes, there will always be the need to use sentinels and put the
logic inside the function; but there are plenty where code will
benefit from putting the default into the signature, just as we
already have with early-bound defaults.

It's easy to argue against a feature by showing that it can be abused.
For instance, I could rewrite your def function thus:

def foo():
     for a in x:
         print(a)
     for b in x:
         print(b)

other_func(lambda: [print(a) for lst in x,x for a in lst].append(0)])

Tada! I've worked around a technical limitation. Is this good code?
No. Would some code benefit from a multi-line lambda function?
Definitely.

Workarounds can be horrifically clunky, and then they provide a strong
incentive to do things better. Or they can be fairly insignificant,
which provides a much weaker incentive. (In this case, it's probably
fine to just use def!) But they're still workarounds, and there is
always benefit to being able to expressing your logic without having
to fight the language's limitations.

ChrisA
_______________________________________________
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/H7ZYVDCP4T4KYHUJFDFSEC33UO4NOJPA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to