Use empty string for self

Grant Edwards grante at visi.com
Tue Feb 28 23:35:38 EST 2006


On 2006-03-01, John Salerno <johnjsal at NOSPAMgmail.com> wrote:

>> Yes.  To death.  Executive summary: self is here to stay.
>
> A related thing I was wondering about was the use of 'self' in
> class methods as the first parameter.

It's not a related thing, it's the same thing.

> I understand that right now it is necessary, but is this
> something that the language itself requires,

Yes.  Sort of.  When declaring a function, you have to declare
all of the formal paramters.  For functions that are bound to
class instances as methods, the first formal parameter is the
object instance.  It's common practice to call that parameter
"self", but you can call it something else.

> or just the way it is implemented now?

No.

> It seems like a waste of typing

Typing is free.  At least compared to the costs of the rest of
the life-cycle of a software project.

> to always have to put self as the first parameter in every
> class method.

You could call that first parameter to class methods "s" if you
can't afford the three extra letters (I've got lots of extra
letters, and I can send you some if you like).  If you do call
it something other than self and somebody else ever has to
maintain your code, they'll be annoyed with you.

> Is there no way for it to be implied?

No.

-- 
Grant Edwards
grante at visi.com



More information about the Python-list mailing list