"self" - a python wart or "feature"

Manuel M. Garcia mail at manuelmgarcia.com
Mon Feb 17 01:52:17 EST 2003


On Sun, 16 Feb 2003 21:16:13 -0800, Cere Davis <cere at u.washington.edu>
wrote:
>Thanks but I'm having diffuculty understanding how this FAQ answers my 
>question about requiring self as the first argument in a function.
>I can appreciate clarity of scope for variables but it seems to me that 
>requiring an extra argument in a function that is allready indented into 
>the class
>to be unnecessary.  From what little I know about Ruby, it does not 
>require this for function declarations within a class.  

It is because there is absolutely no difference between functions and
methods in Python.  The behavior is very close to Perl's object model.
(Actually, Perl's object model was based on Python's).

This was a design decision.  Python's growth has been very
conservative with regards to adding language constructs.  Since the
only difference between functions and methods is explicit or implied
access to 'self', it was decided that functions would do double duty.

Please try both Python and Ruby, and see which one you are more
productive with.  They have different design philosophies.  Ruby had
the benefit of being designed with a complete object model right at
the beginning.

http://www.python.org/doc/essays/ppt/regrets/PythonRegrets.ppt

There are some things Guido would have done differently with the
benefit of hindsight, but explicit 'self' is not one of them.

Manuel




More information about the Python-list mailing list