Python Tutorial Was: Guido's regrets: filter and map

Terry Hancock hancock at anansispaceworks.com
Tue Nov 26 02:19:46 EST 2002


On Monday 25 November 2002 08:31 pm,  Grant Edwards wrote:
> In article <sss5uus0o18jtdi2lcpp3605vfgscmvmum at 4ax.com>, Courageous wrote:
> > Lambda is an abortion, imo. It should be deprecated, and eventually
> > removed from the language. It doesn't do what it set out to do 
particularly
> > well, and suffers from the double sin of being a construct that is
> > inherently anti-pythonic. The subset of list comprehensions that can
> > be used to do what map/reduce-lambda do are an example of something
> > that does what it was intended, is clear, and pythonic.

map(), filter(), and reduce() do not represent all of the uses for filter,
and thus, they can't all be replaced by list comps (BTW, I never used
reduce, never understood what it was good for, and don't immediately
see how it can be done using list-comps -- would be genuinely interested
in seeing a couple of example if anyone's willing). 

So I think lambda still has a place, though I wouldn't want to increase
its capabilities (such as making non-expression functions possible).

> I find lambda quite useful for creating simple anonymous functions to pass
> to GUIs as button commands and the like.  I suppose the same effect could be
> obtained by adding a couple more lines to define a temporarily-named
> function, but then I'd have to think up a name.  I've been known to waste
> hours trying to come up with names for new computers. I'm not quite so
> indecisive about functions, but it does seem to be one of my weak points.

Agreed -- the general pattern of passing functions as first-class objects
is supported by providing the simplicity of lambda for the degenerate
case, just like numerical or aggregate data literals support passing 
variables (do I recall correctly that you couldn't pass literals to functions
in Pascal?  I remember being very annoyed by that, coming from 
Fortran).

As for the pain of thinking up a name -- I think it's actually a good
sign. It shows you care.  Good names are a real benefit to your own
future self and to anyone else who must read your code. Though they
weren't primarily interested in programming but in websites, I found the
book "Information Architecture" (O'Reilly), to be very influential in
my thinking about variable names and other "labels" -- which is the
term they use.  Not saying I always live up to the ideal, but it gave me
an ideal to try for. ;-D

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list