Reasoning behind 'self' parameter in classes?

Robert Dailey rcdailey at gmail.com
Wed Jul 30 15:27:55 EDT 2008


On Wed, Jul 30, 2008 at 1:03 PM, Brett g Porter <bgporter at acm.org> wrote:

> Robert Dailey wrote:
>
>  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 Python!"
>>
>>
> Fredrik Lundh has written a  very clear explanation of this at
> http://effbot.org/pyfaq/why-must-self-be-used-explicitly-in-method-definitions-and-calls.htm
>
> (or http://bit.ly/3EUiCf if you don't feel like stitching that URL back
> together...)
>

This sounds like an article of opinion. He's not really given any reasons
other than "Well, it makes this easier or look better". True that
declarations are the determining factor in C/C++, however I was thinking of
more or less an implied 'self'. For example:

# Consider this normal syntax:
class MyFoo:
    def DoFoo( self ):
        self._member = 6

# Elimintating 'self' in the parameter list should still work as far as the
# interpreter is concerned, since 'self' in this case now acts like 'this'
# in C++. The below code should be equivalent.
class MyFoo:
    def DoFoo():
        self._member = 6

Given the code samples above, is there any technical reason why this cannot
be done? Thanks for the input guys, and thanks more over for keeping this
easy-going.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080730/7337729b/attachment.html>


More information about the Python-list mailing list