Guido's new method definition idea

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Dec 6 07:02:54 EST 2008


Antoine De Groote:
> Allowing "$" as a substitute for "self" wouldn't require this new syntax.
> class C:
>     def method($, arg):
>         $.value = arg

I think this (that is just sugar) may be a little better:

class C:
    def method($, arg):
        $value = arg

Or even this, combined with the idea suggested in the post by Guido:

class C:
    def $method(arg):
        $value = arg

(Note there's no point after $, it's not currently possible).
Ruby uses @ and @@ for similar purposes.
I agree that the code looks worse, but also shorter to read and write,
so in lines of code that use many instance attributes, that short $
syntax helps keep the line shorter. So I may grow to accept this
sugar...

Bye,
bearophile



More information about the Python-list mailing list