Issue 18648: FP Howto and the PEP 8 lambda guildline (original) (raw)

Created on 2013-08-03 20:58 by terry.reedy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg194301 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-03 20:58
Functional Programming HowTo, near the end, has a section Small functions and the lambda expression http://docs.python.org/3/howto/functional.html#small-functions-and-the-lambda-expression To illustrate, it starts with adder = lambda x, y: x+y print_assign = lambda name, value: name + '=' + str(value) which are now proscribed by PEP 8. "Always use a def statement instead of an assignment statement that binds a lambda expression directly to a name." The text goes on to give the def equivalents and to discourage lambdas. "Which alternative is preferable? That’s a style question; my usual course is to avoid using lambda." But I think the section should instead start with lambda examples that would be acceptable in the stdlib.
msg194320 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2013-08-04 01:13
I would just change "my usual course is to avoid using lambda" to "PEP 8 prescribes using def." Note that PEP 8 itself displays f = lambda x: 2*x as an example of what not to do. I see no problem with the current examples.
msg194821 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-08-10 17:24
IMHO that part should not suggest to use lambdas as small functions, so I would drop the example with adder/print_assign and the discussion about lambdas vs defs (the example that uses defs can stay), and keep the rest (from the "reduce" example).
msg233247 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2014-12-31 16:13
This section is trying to illustrate the reasoning that leads to PEP 8's conclusion, so I don't want to just replace it with a reference to PEP8.
History
Date User Action Args
2022-04-11 14:57:48 admin set github: 62848
2014-12-31 23:15:29 berker.peksag set stage: needs patch -> resolved
2014-12-31 16:13:49 akuchling set status: open -> closedresolution: wont fixmessages: +
2013-08-10 17:24:16 ezio.melotti set nosy: + rhettinger, ezio.melottimessages: +
2013-08-04 01:13:19 belopolsky set nosy: + belopolskymessages: +
2013-08-03 20:58:16 terry.reedy create