A critic of Guido's blog on Python's lambda

M Jared Finder jared at hpalace.com
Tue May 9 01:47:57 EDT 2006


Alex Martelli wrote:
> Joe Marshall <eval.apply at gmail.com> wrote:
>    ...
>> If you language allows unnamed integers, unnamed strings, unnamed
>> characters, unnamed arrays or aggregates, unnamed floats, unnamed
>> expressions, unnamed statements, unnamed argument lists, etc.  why
>> *require* a name for trivial functions?
> 
> I think it's reasonable to make a name a part of functions, classes and
> modules because they may often be involved in tracebacks (in case of
> uncaught errors): to me, it makes sense to let an error-diagnosing
> tracebacks display packages, modules, classes and functions/methods
> involved in the chain of calls leading to the point of error _by name_.
> 
> I think it's reasonable to make a name a part of types for a different
> reason: new types are rarely meant to be used "just once"; but also, if
> during debugging any object is displayed, it's nice to be able to show,
> as part of the display, "this object is of type X and ...", with X shown
> as a name rather than as a complete (thus lengthy) description. (any
> decent interactive shell/debugger will let you drill down into the
> details as and when you need to, of course, but a well-chosen name can
> be often sufficient during such interactive exploration/debugging
> sessions, and therefore save time and effort).

Any time you want an anonymous function (or class, or type, or number) 
it would be because that thing is sufficiently small and simple that the 
best name for it is the code itself.  In one game I worked on, there was 
a function named canPerformAction_and_isNotActionInQueue.  It was a 
simple, one line function:

bool canPerformAction_and_isNotActionInQueue( Action action ) {
   return canPerformAction( action ) && !isActionInQueue( action );
}

There was no better, more abstract name, as the design required this 
logic for a completely arbitrary reason -- so arbitrary it changed 
multiple times in development.  For a little while it was used in two 
places.  Then one of those places changed to have only the 
isActionInQueue part.  There was no useful abstraction to be made, and 
it is in cases like these (which come up a lot when using functions as 
parameters) where anonymous functions are a win.

   -- MJF



More information about the Python-list mailing list