[Python-Dev] None as a keyword / class methods

Christian Tismer tismer@tismer.com
Thu, 23 Mar 2000 21:21:09 +0100


Yo,

gvwilson@nevex.com wrote:
> 
> Hi, Christian; thanks for your mail.
> 
> > What I would propose instead is:
> > make the parameter name "self" mandatory for methods, and turn
> > everything else into a static method.
> 
> In my experience, significant omissions (i.e. something being important
> because it is *not* there) often give beginners trouble.  For example,
> in C++, you can't tell whether:
> 
> int foo::bar(int bah)
> {
>   return 0;
> }
> 
> belongs to instances, or to the class as a whole, without referring back
> to the header file [1].  To quote the immortal Jeremy Hylton:
> 
>     Pythonic design rules #2:
>          Explicit is better than implicit.

Sure. I am explicitly *not* using self if I want no self. :-)

> Also, people often ask why 'self' is required as a method argument in
> Python, when it is not in C++ or Java; this proposal would (retroactively)
> answer that question...

You prefer to use the explicit keyword None? How would you then deal
with

def outside(None, blah):
    pass # stuff

I believe one answer about the explicit "self" is that it should
be simple and compatible with ordinary functions. Guido had just
to add the semantics that in methods the first parameter
automatically binds to the instance.

The None gives me a bit of trouble, but not much.
What I would like to spell is

ordinary functions                    (as it is now)
functions which are instance methods  (with the immortal self)
functions which are static methods    ???
functions which are class methods     !!!

Static methods can work either with the "1st param==None" rule
or with the "1st paramname!=self" rule or whatever.
But how would you do class methods, which IMHO should have
their class passed in as first parameter?
Do you see a clean syntax for this?

I thought of some weirdness like

def meth(self, ...
def static(self=None, ...           # eek
def classm(self=class, ...          # ahem

but this breaks the rule of default argument order.

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home