Why the 'self' argument?

Grant Edwards grante at visi.com
Fri Sep 5 17:34:05 EDT 2003


In article <vlhtm1bmc7m295 at news.supernews.com>, John Roth wrote:

>> There's no difference in the sense that a method is simply a
>> function whose first parameter refers to the class instance to
>> be worked on.  No magic words, no "undeclared" parameters.  It
>> means that in my demo code in limitcases.py (somewhere in the
>> newsgroup lately) I can say
>>
>>     limitcases.Lowest.__str__ = lambda x: "-Infinity"
>>
>> to give the Lowest class a new method sans ennuis.
> 
> But why do it that way?

So that there's no difference between a function and a method.

Simplicity and orthogonality are good things -- despite what
C++ proponents thing. 

> Neither Java nor Ruby require giving the instance a name.

So?  

Personally I don't like invisible, implied, automatic stuff
like that.

Can't stand automatic transmissions either -- the damn things
have no idea what's ahead, and always seem to be in the wrong
gear at critical moments.

> Hence my comment that requiring it is more complex than not
> requiring it.

No, it's more complex the Java/Ruby way, since you have to have
two sets of rules for what a name means depending on whether
you're inside a "normal" function or a method.  In Python
there's just one set of rules -- mostly.

I have enough trouble remembering how the stuff I design works. ;)

I don't want to have to keep track of more scoping/name-space
rules than absolutely necessary.

-- 
Grant Edwards                   grante             Yow!  Intra-mural sports
                                  at               results are filtering
                               visi.com            through th' plumbing...




More information about the Python-list mailing list