Express What, not How.

Lulu of the Lotus-Eaters mertz at gnosis.cx
Wed Oct 15 03:00:50 EDT 2003


"Rainer Deyke" <rainerd at eldwood.com> wrote previously:
|However, I think I can make an even stronger case for anonymous functions
|from my own code, which is littered with lambda expressions such as 'lambda:
|1', 'lambda: 0', and 'lambda: None'.  Giving those mini functions individual
|names would be an atrocity

Let's say I created a module lambdas.py (and generalized your functions):

    OneFunc = lambda *a,**kw: 1
    ZeroFunc = lambda *a,**kw: 0
    NoneFunc = lambda *a,**kw: None
    ...etc...

In my application, I might have:

    from lambdas import *
    ...
    widget(param1, param2, callback=isCond and myFunc or NoneFunc)

Where exactly does the atrocity arise?!  If anything, it's slightly more
readable than Deyke's little lambdas (and a little more concise too).

Yours, Lulu...

--
Keeping medicines from the bloodstreams of the sick; food from the bellies
of the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons.  Intellectual
property is to the 21st century what the slave trade was to the 16th.






More information about the Python-list mailing list