Guido's new method definition idea

bearophileHUGS at bearophileHUGS at
Sat Dec 6 17:42:28 CET 2008

Steven D'Aprano:
> If a line of code uses too many instance attributes to fit comfortably on
> a line, spread it over two lines. There is no newline shortage, they are
> a renewable resource.

Splitting lines is generally possible, but sometimes it's not I want,
for example to keep a formula whole.

And splitting lines increases line count. Increasing line count may
reduce the amount of code you can see in a screenshot, and this may
decrease a little the programmer's ability to understand code.

(I am not suggesting to cram everything into one or few lines, like in
K language: regarding code size there's an optimal middle point
between K/APL and Ada/certain Java. Still, typing "self." very often
requires time, and even if you are lucky to have an IDE that helps you
write that faster, the code uses lot of space anyway).

That's why I say that the following code, while looking a little ugly,
may be a little "better" anyway (and maybe even more readable):

class ThisIsAClass:
    def $some_method(arg1, arg2):
        $value = arg1 + $foo + $bar + $baz * arg2

Than the current syntax:

class ThisIsAClass:
    def some_method(self, arg1, arg2):
        self.value = arg1 + + + self.baz * arg2


More information about the Python-list mailing list