On Nov 23, 2007 11:54 PM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > 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. [gibberish] > which to my eyes has too much whitespace, but the alternative is worse: > math.sqrt(.x*.x + .y*.y + .z*.z)
This is merely your personal preference and as such, it is not possible to argue or put in absolute terms. > and this is positively painful to try to read, it looks like line-noise: > math.sqrt(.x*.x+.y*.y+.z*.z) At least it is 12 characters less line-noise than math.sqrt(self.x*self.y+self.y*self.y+self.z*self.z). > The correct solution to your example is to get rid of the attribute > lookups from the expression completely: No it is not. The "solution" is nothing more than a silly band-aid thrown out by people who cannot comprehend that Python may not be perfect in every little detail. > 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. timeit -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list