[Python-Dev] PEP 8 modernisation
Alexander Shorin
kxepal at gmail.com
Fri Aug 2 13:02:01 CEST 2013
On Fri, Aug 2, 2013 at 1:10 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Lambda was almost removed in Python 3.
>
>>
>> Using `dict` to store lambdas:
>>
>> > op = { 'add': lambda x,y: x*y, 'mul': lambda x, y: x+y}
>>
>> Shows the hack to bypass PEP8 guides. Do you like to see code above
>> instead of:
>>
>> add = lambda x,y: x*y
>> mul = lambda x, y: x+y
>>
>> Probably, I don't since dict is a blackbox and I have to check things
>> first before use them.
>
> People are free to write their own style guides that disagree with pep 8 (a
> point which is now made explicitly in the PEP).
>
>>
>> Disclaimer: I don't try to stand for lambdas, I'm not using them
>> everywhere in my code, but I'd like to know answer for the question
>> "Why lambdas?". Currently, it is "Handy shorthand functions - use them
>> free", but with new PEP-8 statement I really have to think like
>> "Lambdas? Really, why?".
>
> Use them for an anonymous function as an expression. All PEP 8 is now saying
> is that giving a lambda a name is to completely misunderstand what they're
> for.
>
> Cheers,
> Nick.
Thanks for explanations, Nick, I'd got the point.
--
,,,^..^,,,
More information about the Python-Dev
mailing list