[Python-ideas] Proposal for function expressions
Carl Johnson
cmjohnson.mailinglist at gmail.com
Tue Jul 14 13:41:52 CEST 2009
This idea seems to be almost identical to my thread from November,
"Proposal for Ruby-style anonymous block functions (that don't kill
the indention)":
http://mail.python.org/pipermail/python-ideas/2008-November/002340.html
The real difference is that your proposal uses & (which is a bad idea,
since & already has a meaning: __and__) and in
foo() do:
BODY
it implicitly injects the BODY function into the args of foo, which
violates Explicit Is Better Than Implicit.
I agree though that sometimes rather than doing
def spam():
BODY
result = foo(spam)
you would rather do
result = foo(spam*) *To Be Defined on the next line, OK!
def spam():
BODY
because it reads better. As I understand it, this was the reason the
decorator syntax was invented. Basically,
@classmethod
def foo():
BODY
reads better than
def foo():
BODY
foo = classmethod(foo)
so decorators are just syntatic sugar to improve readability.
So, I agree with the basic motivation of your proposal, but I think
the specifics of it aren't as good as my old one (although, I *would*
think that, wouldn't I?) and from experience, I expect the BDFL to
come and give you -2 in a couple days if the thread keeps up…
In terms of refining my old proposal, it strikes me that ! isn't used
in Python currently. If we have to use a sigil of some sort, we could
try:
new_list = sorted(old_list, key=!keyfunc)
def keyfunc(item):
normalize data…
or something to that effect with the general semantic being that !
means "here comes a variable name, I will define this variable on the
next line, please wait for it!"
2-cents-ly-yrs,
-- Carl Johnson
More information about the Python-ideas
mailing list