classification
Title: FP Howto and the PEP 8 lambda guildline
Type: Stage: resolved
Components: Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: akuchling, belopolsky, ezio.melotti, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2013-08-03 20:58 by terry.reedy, last changed 2014-12-31 23:15 by berker.peksag. 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
2014-12-31 23:15:29berker.peksagsetstage: needs patch -> resolved
2014-12-31 16:13:49akuchlingsetstatus: open -> closed
resolution: wont fix
messages: + msg233247
2013-08-10 17:24:16ezio.melottisetnosy: + rhettinger, ezio.melotti
messages: + msg194821
2013-08-04 01:13:19belopolskysetnosy: + belopolsky
messages: + msg194320
2013-08-03 20:58:16terry.reedycreate