Extending Python Syntax with @
claird at lairds.com
Thu Mar 11 13:55:20 CET 2004
In article <2f9050pq22u53o7aqo9i8ebqj11vo9kilg at 4ax.com>,
David MacQuigg <dmq at gain.com> wrote:
>going to help me write some code, I won't have time to study it. My
>understanding of lambda functions is simply that they are a way to
>squeeze functions into a tight space:
>list_of_funcs = [(lambda x: 2**x), (lambda x: 3**x), (lambda x: 4**x)]
>If you are not concerned about space, simply use normal defs:
>def f2(x): return 2**x
>def f3(x): return 3**x
>def f4(x): return 4**x
>list_of_funcs = [f2, f3, f4]
>Is there any other reason in Python to use lambdas?
In fact, *that*'s not a reason. Part of tribal lore--a true,
documented part, by the way--is that Big Cheese Guido depre-
cates lambdas. He says they're a mistake, and people shouldn't
be using 'em. Whenever you feel like a lambda, define a named
function; it forces the developer to come up with a name for
the operation, and that's likely to make the code more read-
able (I'm slightly abbreviating the argument here).
Space, in the sense you're using it above, should NOT concern
Pythoneers. Correctness and clarity of express should.
It pains my sensitivities every time you claim lambdas are
just a way of making functions "small". Again, I understand
how natural that is from your background. Around this
mathematician, 'twould be less distracting to run your finger-
nails down a chalkboard.
I think this ties back to your broader original propositions:
the Python aesthetic assesses little merit for the brevity of
@-anything, and much for the presumed evocativeness of "yield".
An abundance of *good* keywords is a good thing. That's
definitely not the attitude of all languages.
Cameron Laird <claird at phaseit.net>
More information about the Python-list