A friendlier, sugarier lambda -- a proposal for Ruby-like blocks in python
Kay Schluehr
kay.schluehr at gmx.net
Sat Oct 14 03:40:57 EDT 2006
Paul Rubin wrote:
> brenocon at gmail.com writes:
> > deferred = fetchPage('http://python.org')
> > def _showResponse(response)
> > print "fancy formatting: %s" % response.text
> > deferred.addCallback(_showResponse)
> >
> > Lots of Twisted code has to be written backwards like this.
>
> But that's just ugly. The fetchPage function should take the callback
> as an argument. In an asynchronous system it would even be buggy.
> What happens if the page fetch completes before you add the callback?
As long as the fetchPage object does not start fetching right after
being constructed but only after applying an additional activate()
method the code is not buggy. I'm not sure about this design either. Is
_showResponse really that characteristic for fetchPage that it can't be
an object method? Spreading tiny function definitions all over the code
may be finally not such a good idea compared with a few generic methods
that get just called? OO might run out of fashion these days but Python
is not Java and Pythons OO is pretty lightweight.
More information about the Python-list
mailing list