[Twisted-Python] RPC design questions

Tobias Oberstein tobias.oberstein at tavendo.de
Tue Aug 23 15:13:48 EDT 2011


Thanks for your advice .. that's what I was looking for;)

Makes sense, I'll stick to your advice, kick the subclassing approach and the stuff with the reordering version rcall().

That leaves "partial" and "lambda"

      # Option 1 : prints 31
      d2 = self.call("square", 6).addCallback(lambda res: self.call("sub", res, 5)).addCallback(self.show)

      # Option 3 : prints -31
      d4 = self.call("square", 6).addCallback(partial(self.call, "sub", 5)).addCallback(self.show)

Lambda is the most general, since it can insert the previous deferred's result anywhere in the next call.
Partial only simulates append result to end of args of next call.
But lambda is also most verbose.

I'll sleep one night and then see if I document and endorse both or only lambda.

Obviously, I can't hinder anyone using both. Built in stuff.

Thanks again,
Tobias



Von: twisted-python-bounces at twistedmatrix.com [mailto:twisted-python-bounces at twistedmatrix.com] Im Auftrag von Glyph Lefkowitz
Gesendet: Dienstag, 23. August 2011 20:30
An: Twisted general discussion
Betreff: Re: [Twisted-Python] RPC design questions


On Aug 23, 2011, at 10:37 AM, Tobias Oberstein wrote:


class AutobahnDeferred(Deferred):
  def call(self, *args):
     return self.addCallback(self.protocol.rcall, *args)

Pro:    most terse
Con:    only supports single callback no errback


Con: subclassing in general is a bad idea.  Subclassing Deferred is an even worse idea.  What if Deferred one day gets a new method called 'call' that does something different?  Your code would all break.

Anything why I shouldn't do?

Providing three different ways to do the same thing just so that you can use different syntax depending on your mood is a recipe for making your code hard to read.  Pick one style, stick to it as much as possible - consistency is more important than the benefits of any one particular style :).

(Except the subclassing one.  Don't do that.)

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20110823/bd07c6cd/attachment.htm 


More information about the Twisted-Python mailing list