the annoying, verbose self
Neil Cerutti
horpner at yahoo.com
Sat Nov 24 01:55:14 CET 2007
On 2007-11-23, BJörn Lindqvist <bjourne at gmail.com> wrote:
> The big deal is that "self." occupies important horizontal
> screen real estate. That is, it is usually not self in itself
> that is problematic, but the overflowing lines is. Take this
> silly vector class for example:
>
> 1 class Vector:
> 2 def __init__(self, x, y, z):
> 3 self.x = x
> 4 self.y = y
> 5 self.z = z
> 6 def abs(self):
> 7 return math.sqrt(self.x * self.x + self.y * self.y +
> self.z * self.z)
>
> 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.
-1 Refactoring is a more expedient response than language
redesign.
def sum_of_squares(*args):
return sum(arg*args for arg in args)
--
Neil Cerutti
More information about the Python-list
mailing list