The need to put "self" in every method

John Roth newsgroups at jhrothjr.com
Tue May 31 12:19:14 EDT 2005


"Fernando M." <fernandomirandamuro at gmail.com> wrote in message 
news:1117554344.938440.54700 at g14g2000cwa.googlegroups.com...
> Hi,
>
> i was just wondering about the need to put "self" as the first
> parameter in every method a class has because, if it's always needed,
> why the obligation to write it? couldn't it be implicit?
>
> Or is it a special reason for this being this way?

There are two different issues.

1. If self was made a keyword, there would be no need for
it in the method header. However, that would be a major
incompabible change affecting almost every script in existance.
Also some people use other words than self. (It would,
by the way, result in a performance improvement.)

2. There's been some talk of making the '.' operator allow an
implied instance. I'm not sure what the status of this is.

These two are actually separate issues; either could be
done without the other.

John Roth

> Thanks.
> 




More information about the Python-list mailing list