[Python-ideas] Thoughts on lambda expressions

Paul Moore p.f.moore at gmail.com
Thu Mar 3 04:22:11 EST 2016


On 3 March 2016 at 00:37, Abe Dillon <abedillon at gmail.com> wrote:
> On Wednesday, March 2, 2016 at 5:04:10 PM UTC-6, Paul Moore wrote:
>>
>> So the basic problem for me is that the proposal doesn't offer huge
>> benefits, and it's solving a problem that people should probably try
>> to avoid in the first place.
>
>
> Yes, that's why I said, "I'm not sure if this should actually be
> implemented". People talk a lot about the 'expressiveness' of lambda
> statements, but the situations where they're actually more expressive than
> obfuscating are very rare and usually involve some idiom that makes the
> signature definition all but vestigial.
>
> filter(lambda num: num > 3, nums)
> # all that boiler plate before the part we really care about: filter(num >
> 3, nums)
>
> This is a minor improvement suggestion with some insight I've gleaned on
> code readability (putting the meat before the potatoes often improves
> readability, as does using more common english words).

Understood, and (IMO) you're right about the improved readability. I
think the costs mean that it's not worth implementing (as you
suspected) but it's still a good principle ro remember.

I actually quite liked Perl's "trailing control flow" constructs for
much the same reason (put the key thing first). Using Python-like
syntax (because I can't remember Perl these days):

    x = default if x is None
    x = x + 1 while fn(x) < 100

The problem with these being Perl's usual problem - they add yet more
ways of saying the same thing we can already do.

Paul


More information about the Python-ideas mailing list