how to give an object as argument for a method

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Thu Mar 7 08:58:25 EST 2002


----- Original Message ----- 
From: "Marco Herrn" <herrn at gmx.net>


> On Thu, Mar 07, 2002 at 03:28:09PM +1300, Greg Ewing wrote:
> > Marco Herrn wrote:
> > > 
> > > hmm, do I have to implement that in _every_ method or just in
> > > methods who use the 'self' statement?
> > 
> > In every method. The instance is always passed in
> > as the first parameter, so there must be a parameter
> > there to receive it, even if it's not used inside
> > the method.
> 
> Is there a reason why this is just a convention? It seems (because it is
> such a _strong_ convention) that this should be a real feature of the
> language. I mean that there could be a reserved word "self" which is
> there all the time, so that one doesn't hast to do this himself.

Python is by nature a pragmatic language, and one design philosophy
which is considered very important is "Explicit is better than implicit."
This particular feature, namely that the first method argument is "self",
is simply how it is in the language.  You can use "I" as one poster 
suggested, or "me" as another mentioned some time ago; readability isn't
harmed much.

I'm pretty lazy, but four characters isn't that much work even if you have
to type them over and over in some cases.  Isn't it Java that uses an 
implicit "this" variable, or is that Javascript?  Python programmers 
prefer explicit declarations.






More information about the Python-list mailing list