[Tutor] self self self

Blake Winton bwinton@tor.dhs.org
Mon, 17 Jul 2000 21:36:52 -0400


* Remco Gerlich <scarblac@pino.selwerd.nl> [000717 20:04]:
> On Mon, Jul 17, 2000 at 12:13:32PM -0700, Isaac wrote:
> > in java classes, the 'self' namespace is automatically available.
> > instance methods automatically include the self ('this' in java)
> > as the first argument, so we don't have to worry about it.  And
> > the same goes for accessing instance vars and methods.
> Well, you could use 's.' instead of 'self.'...
> 
> I don't think it will go. It makes code clear (you can tell the
> difference between instance and local variables immediately). How
> would Python tell the difference between the local namespace, the
> global namespace and the instance's namespace? In Java it's
> necessary to declare variables and that info can be used, but as
> Python is so dynamic, I don't see that happen.

In most of the Java coding standards I've seen, it is strongly
recommended that you use "this." in front of every instance variable.
For precisely the reasons stated above.  It's far easier to see what
variables in a function are local, and what variables belong to the
object.

> It would be irritating if every loop counter or so you used in a
> method would be added to the instance...

It's not on assignment, just on reference.  So stuff you create in a
method is local to that method, but if you use a variable that's not
local to the method, Java automatically checks the instance for you.

Later,
Blake.
-- 
9:28pm up 2 days, 20:55, 1 user, load average: 0.00, 0.00, 0.00