[Tutor] Why lambda could be considered evil

Scot W. Stevenson scot@possum.in-berlin.de
Tue, 27 Aug 2002 20:12:18 +0200


Hello Alan, 

> However understanding lambda expressions is one of
> those "change your life" type discoveries in programming.

Hmpf. Maybe my life isn't ready to be changed quite just yet =8). 

> The class statement is part of OO and not a rip off
> from C++, similarly lambda is part of functional
> programming. 

You could also add that list comprehensions come from something called 
Haskell, and generators from Icon, and I would agree. However, I see a 
major difference between classes, generators, and list comprehensions on 
the one hand and lambda, print >> file, and print "Funny %s characters" % 
variable on the other: The syntax of classes, generators and list 
comprehensions was changed to Python's way of doing things, while lambda 
and the two prints retain their "native" we-use-special-characters syntax. 

While discussing list comprehensions and their Haskell source in recipe 
2.11 in the "Python Cookbook", Nathaniel Gray points out that Python tends 
to use keywords where other languages use punctuation, so that Haskell 
list comprehension terms such as 

[y | y <- xs, y < x]

are turned into something like this in Python: 

[y for y in xs if y < x]

(note that I couldn't even order a beer in Haskell, so this might not be 
the exact equivalent). Same thing goes for the class statement, which was 
adapted to Python: The very syntax has been turned Pythonic, and uses 
keywords instead of strange arrow thingies or double colons or whatever 
the other languages use. 

But the other three examples weren't absorbed into the language, they were 
just copied from C or Lisp, and they kept their native "punctuation" 
syntax. I'm not sure I understand why (except for the mighty C and Lisp 
lobbyists, which are probably linked to the Illuminati and Knights 
Templar), because 

print >> file, 'Print me'    could have been   
print to file, 'Print me'     or even better
print 'Print me' to file 

and 

print "Hello Mr. %s" % name    could have been 
print "Hello Mr. %s" using name  or
print "Hello Mr. %s" with name 

Which looks a lot more Pythonic to me. I've read the PEPs and BDFL 
pronouncements and I'm still not convinced. Given the number of English 
words in the OED, I'm _certainly_ not convinced that "keyword inflation" 
is going to be a problem anytime soon. And using keywords is just so much 
more consistant with the rest of the language, and better for human 
readers.

> Of course it would help if lambdas were fully implemented
> to allow multi line 'arbitrary' blocks of code rather
> than just single line expressions....

I'm having some trouble visualizing that - could you give an example (in 
pseudocode or whatever) of what that would look like? 

> > 3. The name is just plain stupid. ....
> > be intuitive if you've spent the last 20 years programming Lisp,

> Or studying lambda calculus!

Well, I'm not sure if the majority of Python users have actually done that, 
either =8)...I dimly remember having had calculus in school at some point, 
but I'd be hard pressed to come up with any details...

I think this discussion can be reduced to one question: Is Python, or 
rather, Python's syntax, geared more towards computer science people with 
a strong background in various computer languages and math, or is it aimed 
more at what I would call the educated computer user who has some 
background, but nothing formal? 

I would argue that so far, it is mostly geared from the educated public, 
not specialists. My Exhibit One would be the new form of division, which 
is going to drive computer science people up the wall, but "real" people 
will just love because it is "real" division. If that is in fact so, then 
lambda and the two print forms mentioned above don't quite fit in.

Y, Scot

-- 
  Scot W. Stevenson wrote me on Tuesday, 27. Aug 2002 in Zepernick, Germany   
       on his happy little Linux system that has been up for 1694 hours       
        and has a CPU that is falling asleep at a system load of 0.01.