On Fri, 23 Nov 2007 23:38:24 +0000, BJörn Lindqvist wrote: > I like that a lot. This saves 12 characters for the original example and > removes the need to wrap it. > > 7 return math.sqrt(.x * .x + .y * .y + .z * .z) > > +1 Readability counts, even on small screens.
-2 Readability counts, and your example is a lot less readable. For your example to be even *slightly* readable, you have to fill the expression with excessive whitespace. A little bit of whitespace is good. Too much breaks the flow of the expression and hurts readability. Or perhaps I should say: T o o m u c h b r e a k s t h e f l o w . . . You write: math.sqrt(.x * .x + .y * .y + .z * .z) which to my eyes has too much whitespace, but the alternative is worse: math.sqrt(.x*.x + .y*.y + .z*.z) and this is positively painful to try to read, it looks like line-noise: math.sqrt(.x*.x+.y*.y+.z*.z) The correct solution to your example is to get rid of the attribute lookups from the expression completely: def abs(self): x, y, z = self.x, self.y, self.z return math.sqrt(x**2 + y**2 + z**2) It's probably also faster, because it looks up the attributes only once each, instead of twice. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list