[Python-3000] A plea for anonymous functions

Terry Reedy tjreedy at udel.edu
Thu Nov 16 23:46:44 CET 2006


"Antoine" <solipsis at pitrou.net> wrote in message 
news:52661.62.39.9.251.1163684950.squirrel at webmail.nerim.net...
>>      def handle_response(record):
>>          format_expanded(li.content, response.related)
>>      server.get_synset_link(handle_response)
>
> As already mentioned, the problem with this idiom is that code that is
> executed *after* appears *before* the "get_synset_link".

*To me* you have this backwards.  The function-object creation code is 
executed *before* the call that passes that object.  This is true whether 
it is placed before, as above, or nested within, as you and Tomer prefer.

> It makes the code less straightforward to write

*To you*.

> and especially to read

*To you*.

I (and many others, apparently) am less comfortable reading deeply nested 
code inside out than perhaps you and Tomer.  If a function body is more 
complicated than 'return <expression>', I prefer to have it factored out.

> (and having readable code is important).

To both of us, but we differ at least slightly in what is most readable.

Terry Jan Reedy





More information about the Python-3000 mailing list