Deprecate self

Jeremy Hylton jeremy at digicool.com
Wed Apr 18 10:49:12 EDT 2001


>>>>> "MvL" == Martin von Loewis <loewis at informatik.hu-berlin.de> writes:

  MvL> whisper at oz.net (Dave LeBlanc) writes:
  >> Since self is used for every method of every class, isn't it a
  >> bit redundant? I don't know of another OO language that makes you
  >> manually carry around the "this"/"self" pointer/reference...

  MvL> In Smalltalk, invocations of operations on self always require
  MvL> to provide the self argument. You don't have to declare it as a
  MvL> method argument, though.

Modula-3 was mentioned in another post.

There is a reason other than simple clarity (I like using an explicit
self) for this approach.  Python's rules for local variables would
interfere with attribute access.  Since Python eschews variable
declarations, any assignment to a name inside a code block makes that
name a local variable.  By this rule alone, there would never by a way
to assign to an instance variable :-).  You'd need a mechanism like
the global statement to say "This name isn't a local."

We had an opportunity to change the attribute access approach when
nested scopes were introduced, but we went out of our way (well, sort
of) to preserve the self.attr approach.

Jeremy






More information about the Python-list mailing list