Why the 'self' argument?

John Roth newsgroups at jhrothjr.com
Fri Sep 5 13:36:45 EDT 2003


"Grant Edwards" <grante at visi.com> wrote in message
news:3f58b1f6$0$155$a1866201 at newsreader.visi.com...
> In article <vlhba85atlte07 at news.supernews.com>, John Roth wrote:
> >
> > "Grant Edwards" <grante at visi.com> wrote in message
> > news:3f58a2bd$0$156$a1866201 at newsreader.visi.com...
> >> In article <vlh7otscuo8gb1 at news.supernews.com>, John Roth wrote:
> >>
> >> > Technically, it would be possible to make "self" a reserved
> >> > word, and not have to put it in the method declaration.
> >> > However, there are a lot of people who use something other than
> >> > the word "self," so that would break existing code.
> >>
> >> It would also make the language more complex and irregular.
> >
> > How?
>
>  1) It would add a reserved word.

So? For most people, self *is* a reserved word anyway. A lot of
novices think it is. Making it official simplifies things, IMO.

>  2) It would mean that there's some sort of difference between
>     a function and a method.

I don't understand your point. There is currently a difference
between a function and a method that could be eliminated by
making self a reserved word and removing it from the method
header. Or have you never tried to invoke a method from the
wrong context and gotten the "unbound method" error?

There's no reason why a function in the module space couldn't
use self to refer to the module. It would simplify things by
removing much of the need for the global keyword.

John Roth
>
> -- 
> Grant Edwards






More information about the Python-list mailing list