Python misconceptions in IBM Ruby article...

Moshe Zadka moshez at math.huji.ac.il
Fri Feb 18 00:45:52 EST 2000


On Fri, 18 Feb 2000, John Farrell wrote:

> I agree that Python's OO features feel added on. Consider:
> 
>  * You have to pass self to each member function. There's no obvious
>    requirement that self need actually be the bound instance.

Huh? ``self'' is passed automagically to each member function.

consider

class Spam:

	def eggs(self):
		self.x = 1

a = Spam()
a.eggs()

Where did you see me passing ``self'' to a.eggs() explicitly?

>  * In a method, fields of the bound instance need to be referenced
>    through the self parameter, because the scoping rules do not understand
>    about instance variables.

That's because Python doesn't have declerations. And consider the
following C++ snippet:

class C {
	int i;
	void foo(int i) {this->i = i}
}

So even in C++ (and Java) you might have to reference member variables via
this. Python simply has fewer special cases.

--
Moshe Zadka <mzadka at geocities.com>. 
INTERNET: Learn what you know.
Share what you don't.





More information about the Python-list mailing list