Guido's new method definition idea

Antoine De Groote antoine at vo.lu
Sat Dec 6 08:38:50 EST 2008



bearophileHUGS at lycos.com wrote:
> 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

Well, in this case there would be no need to have the $ in the arguments
list, as it would be like a "keyword", or a keysymbol in this case, like
the "this" keyword in Java for instance.
I dislike this even more than the dotted version.

> 
> 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