[Python-ideas] Query about proposed Multi-line Anonymous Function syntaxes

Nick Coghlan ncoghlan at gmail.com
Sun Oct 12 01:53:55 CEST 2014


On 11 October 2014 09:26, Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> wrote:
> A lot of code in these languages uses different techniques to flatten out
> the "callback hell". The most prevalent is probably deferred/promise
> objects. Although these are borrowed from Twisted from the Python world, the
> way they interact with JS-like syntax arguably makes them more useful there:
> Every callback is defined as the argument to a method on a promise, which
> means they start in a consistent place, toward the left edge of the screen,
> etc., and they rarely nest, which avoids most of the problems with inline
> function definitions while still allowing the benefits (not having to define
> the functions out of order, or give them meaningless names).
>
> Of course you could easily come up with a syntax based on one of Nick's two
> PEPs that's even nicer. And the fact that Python has an even better solution
> already (asyncio-style) makes it less interesting. Also, JS definitely
> encourages novices to write unreadable horrible code, even if it allows
> experienced developers to write it more cleanly, and I don't think that's a
> balance Python wants.

Note that it's also *not* a coincidence that some of my own
suggestions are closer to Ruby's blocks than they are to multi-line
lambdas. The exact way blocks work in Ruby is heavily reliant on the
"accept a block as the last parameter to your function" convention,
which makes them hard to adapt to an existing ecosystem like Python's,
but they're still an elegant design pattern worth studying.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list