PEP 312 - Making lambdas implicit worries me, surely it's just the name 'lambda' that is bad...

Jack Diederich jack at performancedrivers.com
Mon Mar 3 09:10:02 EST 2003


On Mon, Mar 03, 2003 at 10:45:15AM +0000, Stephen Horne wrote:
> A major problem with 'lambda' is simply that it is an obscure name.
> Obscure punctuation is usually less of a problem as long as it is easy
> to isolate each construct, and as long as the language does not
> overuse it. A clear pattern of symbols can be almost as explicit as a
> keyword - it is only when the same symbols get used for many different
> purposes that things get severely confusing. However, give something a
> fully explicit name, however, and you risk giving it a name that
> people hate.

My major problem with 'lambda' is just the way it jars the eye when reading
code.  Even with a colorizing editor the fact that it is a word and a longish
one at that[1] adds to the cost of both writing and reading map(), filter(), 
etc.  'lambda' is the only long keyword to always appear in the middle of a
line[2].

I'm a big functional programming fan, but most python user's aren't.
If you took a vote, they'd want the 'lambda' keyword to be renamed 
'lambda_go_away_you_lisper'

A quick grep of src/Lib/*.py shows just 122 lambdas.  There are more asserts
than that.  There are more bitwise operators.  In a code base I've written,
I have twice that number of lambdas in one fourth the lines of code.
Unsuprisingly, I have about the same 'over usage' of map() and filter() and
only two dozen [very simple!] list comprehensions.

I know how the folks who want a ternary operator - ANY ternary operator -
feel, I'd take almost any way to make lambdas look nicer.  I've even considered
recompiling my local Grammar with 'L' replacing 'lambda'.

-jackdied

[1] Keyword list taken from pthon-mode.el
* shorter keywords: is, in, or, if, not, def, del, and, for, pass, elif, 
  else, exec, from, break, print, raise, while, yield, class
* same length keywords: assert, import, except, global, return
* longer keyword(!): continue

[2]
Note that all the other 6 & 7 length keywords are the first thing on a line
global my_var
import foo
return 42
assert(2 + 2 == 5)

'lambda' is always in the middle of a line
new_list = filter(lambda x:x > 0, old_list)





More information about the Python-list mailing list