[Python-Dev] PEP 8: Discourage named lambdas? (original) (raw)
Michael Foord fuzzyman at voidspace.org.uk
Sun May 4 01:56:05 CEST 2008
- Previous message: [Python-Dev] PEP 8: Discourage named lambdas?
- Next message: [Python-Dev] PEP 8: Discourage named lambdas?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Terry Reedy wrote:
Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression
Visually I find the second form very ugly.
The colon indicates to me that a new line is expected, and breaking that expectation breaks my flow of code reading.
I very rarely use lambdas in the form you show, but where you do I prefer them to the single line function.
Michael Foord
The difference in the result (the only one I know of) is that the code and function objects get the generic name '' instead of the more informative (in repr() output or tracebacks) 'somename'. I consider this a disadvantage.
In the absence of any compensating advantages (other than the trivial saving of 3 chars), I consider the def form to be the proper Python style to the point I think it should be at least recommended for the stdlib in the Programming Recommendations section of PEP 8. There are currently uses of named lambdas at least in urllib2. This to me is a bad example for new Python programmers. What do our style mavens think? Terry Jan Reedy
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
- Previous message: [Python-Dev] PEP 8: Discourage named lambdas?
- Next message: [Python-Dev] PEP 8: Discourage named lambdas?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]