[Twisted-Python] Re: My pet peeve ugly coding style

François Pinard pinard at iro.umontreal.ca
Thu Jul 10 16:00:40 MDT 2003


[Tommi Virtanen]

> On Thu, Jul 10, 2003 at 03:33:26PM -0000, Moshe Zadka wrote:
> > > > checkHosts(('moshez.org', 25), ('moshez.org', 22)
> > > > ).addCallback(util.println
> > > > ).addCallback(lambda _: reactor.stop())

> 	Yes, it's legal. It's still ugly.

> 	return foo(      v
> 	).addCallback(bar
> 	).addCallback(baz
> 	).addCallback(quux
> 	).addCallback(thud
> 	).addCallback(xyzzy)

For the above, I would most probably use:

 	return (foo()
                .addCallback(bar)
 	        .addCallback(baz)
 	        .addCallback(quux)
 	        .addCallback(thud)
 	        .addCallback(xyzzy))

The Python mode (for Emacs) agrees with this indentation, given the
surrounding pair of parentheses exists, and this is why I type them.  This
mode (through those having written it: so far that I know, Tim Peters and
Barry Warsaw) is usually a good advisor about correct indentation.

About using dot at the beginning of the line instead of the end, it looks
strange when you are not used to it, but if follows the general principle of
GNU programming standards for C, which is worth for Python as well, that a
continued expression is more legible when the operator is at the start of
the continuation line instead of at the end of the continued one.  I follow
this convention quite systematically, and indeed, the code is more legible.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Twisted-Python mailing list