Reasoning behind 'self' parameter in classes?
rcdailey at gmail.com
Wed Jul 30 18:39:34 CEST 2008
I want to point out first of all that I'm not as familiar with Python as I
should be, and for that reason I question a lot of things because I'm mainly
a C++ programmer and I'm used to certain conveniences. Having said that...
I've always been curious (more so than annoyed) as to why one must
explicitly specify a "self" parameter for member functions in a class in
Python. This seems very "C" like to me, since to do object oriented
programming in C you must devote one parameter to the object itself. In a
higher order language like Python, I would not have expected (and thus am
rather surprised) that this pattern would apply. Is there any particular
reason why 'self' parameters must be specified explicitly? I am curious to
understand the philosophy and design behind this.
In Python 3 will there be any plans to eliminate this syntactic artifact? As
I said, it's not terribly annoying to me but it seems like more of a hack
than anything else. I would feel a bit better if I didn't have to see it. I
don't mean to start any syntax wars or anything, so I hope everyone will
keep an open mind and simply explain the design, rather than defend it. I'm
interested in only facts, and not opinions.
This is an example of a response I'm looking for:
"The self parameter is required because the parser is a bit old and needs to
know the exact object you're referencing"
This is _not_ an example of what I'm looking for:
"Specifying self is a great mysterious thing that we should never question.
Do not question the language! The language is mighty! Don't bring C++ to
I appreciate the community's time.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list