Why self?

Robb Shecter rs at onsitetech.com
Tue Jul 9 17:09:34 EDT 2002


Rich Harkins wrote:
> ...This would happen in Java/C++ too...

(Speaking for Java) Umm, not unintentionally;

> ...Calling Y().pa() would return "hello, world", just like Python.  So this seems 
> to me a problem of general polymorphism rather than Python... 

I disagree!

> ...Java/C++ have the same problem with instance variables too that aren't 
> declared private (private is spelled __ in Python)...

How I see it is that this _isn't_ a "problem" in Java, because the 
standard idiom is for instance variables to be private.  (Or even the 
default protection, which is less than public, and generally accessible 
only by those who have access to the source code - ie. you've already 
forgone black box programming.)

But sticking with methods:  Having a public method in Java (esp. one 
that's not "final") shouts, "Please use me from your client classes! 
And feel free to override me!"  And this public method is clearly 
documented by the standard Java tools.

But most methods aren't public;  Mine are always private - and there is 
never the problem described above.

Robb




More information about the Python-list mailing list