Python-list digest, Vol 1 #10324 - 13 msgs

Jarno J Virtanen jajvirta at cc.helsinki.fi
Sat Apr 6 00:56:08 EST 2002


Fri, 05 Apr 2002 14:29:26 GMT Alex Martelli wrote:

> For example, instead of
> 
> Button(buttonsFrame, text='Squirk', command=lambda: self.squirkIt(23, 45))
> 
> you can code:
> 
> def specificSquirker(): self.squirkIt(23, 45)
> Button(buttonsFrame, text='Squirk', command=specificSquirker)
> 
> It's generally not hard to come up with a name which helps readability.
> I think un-lambdaing your code in this way is a good thing...

I agree.  Furthermore, I don't even think that un-lambdaing that way is
about the maintainability issue per se (ie., 'the "functional" features
make python code unreadable' [1]); it's just that abstracting everywhere
is a good thing.  The highest level of logic at that point is not about
lambdas, it's about "squirking" and that's what you should see in the
source code.  Making routines and giving them names that represent the
highest level of logic, which is not about the actual programming
language code statements [2], is a very powerful tool (available in
other languages too, of course :-). 

(There are other issues, but this abstraction thingy has been
haunting me last couple of days and I had to let out the steam. ;-)

[1] Which I might or might not agree.

[2] Unless writing a programming language compiler or interpreter.




More information about the Python-list mailing list