Proposal for removing self

Ravi Teja Bhupatiraju webraviteja at yahoo.com
Thu Aug 26 09:33:19 CEST 2004


"Brent W. Hughes" <brent.hughes at comcast.net> wrote in message news:<T_7Xc.61360$Fg5.2281 at attbi_s53>...
> When doing object-oriented stuff, it bothers me to have to type "self" so
> many times.  I propose that Python allow the programmer to optionally type
> ".variable" instead of "self.variable" to mean the same thing.  Of course,
> the interpreter would have to be more careful about detecting floats that
> begin with just a period as in ".5".  What are your thoughts?

I know that this has been proposed before and am familiar with the
alternatives commonly suggested. I understand that most Python
programmers are happy with things the way they are in this respect.
But after 3 years of Python, somehow, I still keep forgetting to type
the darn thing. Of course, I always  catch the omission quickly but
that makes me wish there was a better alternative. Python has
generally been about less typing and self seems somewhat contrary to
that.

This following is not a carefully thought one but I would be
interested to know what your opinions are. The following is inspired
by win32all.

<from Python COM  docs>
class HelloWorld:
    _public_methods_ = ['Hello']
    _public_attrs_ = ['softspace', 'noCalls']
    _readonly_attrs_ = ['noCalls']
   
    def __init__(self):
        pass
</from Python COM  docs>

How about having an optional attribute for a class that negates the
requirement for self?

One advantage with this is I can see all the member variables in one
place. Great while reading code.

<sample>
class FooBar:
    __public__ = [Name, Age]
    def setName(name):
        Name = name
</sample>

While I am complaining, a few other peeves ...

Another thing is I dislike is having to use __ for *every* private
variable. For *me* __private__ at the top of the class definition code
would be more elegant. __readonly__ would be another nicety.

Introducing the above attributes into the language would not likely
break any existing Python code.

Just my 2c.



More information about the Python-list mailing list