[Python-Dev] Re: anonymous blocks

Shane Hathaway shane at hathawaymix.org
Wed Apr 20 06:31:36 CEST 2005


Fredrik Lundh wrote:
> Brian Sabbey wrote:
>> doFoo(**):
>>     def func1(a, b):
>>         return a + b
>>     def func2(c, d):
>>         return c + d
>>
>> That is, a suite can be used to define keyword arguments.
> 
> 
> umm.  isn't that just an incredibly obscure way to write
> 
>    def func1(a, b):
>        return a + b
>    def func2(c, d):
>        return c + d
>    doFoo(func1, func2)
> 
> but with more indentation?

Brian's suggestion makes the code read more like an outline.  In Brian's
example, the high-level intent stands out from the details, while in
your example, there is no visual cue that distinguishes the details from
the intent.  Of course, lambdas are even better, when it's possible to
use them:

    doFoo((lambda a, b: a + b), (lambda c, d: c + d))

Shane


More information about the Python-Dev mailing list