On 1 Aug, 2013, at 17:03, Alexander Shorin
...and, if so, why lambda's?(: Without backward compatibility point I see that they are getting "unofficially" deprecated and their usage is dishonoured.
They are still usefull for simple functions that you use in one place, such as the key argument to sorted. By the time you assign a name to the function and give it unittests you may as well use a def-statement and let the function know it its own name. Ronald
-- ,,,^..^,,,
On Thu, Aug 1, 2013 at 6:53 PM, Ronald Oussoren
wrote: On 1 Aug, 2013, at 16:48, Alexander Shorin
wrote: Hi Ronald,
I understand this, but I'm a bit confused about fate of lambdas with such guideline since I see no more reasons to use them with p.9 statement: long lines, code duplicate, no mock and well tests etc. - all these problems could be solved with assigning lambda to some name, but now they are looks useless (or useful only for very trivial cases)
That sounds about right :-)
Note that:
f = lambda x: x ** 2
And:
def f(x): return x ** 2
Are functionally equivalent and use the same byte code. The only differences are that the lambda saves two characters in typing, and the "def" variant has a more useful value in its __name__ attribute.
IMHO The lambda variant also looks uglier (even with the def variant on a single line).
Ronald
-- ,,,^..^,,,
On Thu, Aug 1, 2013 at 6:41 PM, Ronald Oussoren
wrote: On 1 Aug, 2013, at 16:34, Alexander Shorin
wrote: Hi Nick,
On Thu, Aug 1, 2013 at 4:44 PM, Nick Coghlan
wrote: 9. Explicit guideline not to assign lambdas to names (use def, that's what it's for)
Even for propose to fit chars-per-line limit and/or to remove duplicates (especially for sorted groupby case)?
When you do "name = lambda ..." you've created a named function, when you do that your better of using def statement for the reasons Nick mentioned in the PEP.
Ronald
-- ,,,^..^,,, _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/ronaldoussoren%40mac.com