Python misconceptions in IBM Ruby article...

see_plus_plus at my-deja.com see_plus_plus at my-deja.com
Fri Feb 18 12:42:03 EST 2000


This is just a display that you haven't mastered C++.
In your C++ code sample, you on purpose introduced two variables integer
i. The one is the  private data member, and the other is the formal
parameter of function member foo. Just because of that you need to use
'this' to be explicit.
Learn C++ seriously before you try to take on C++.

cpp

In article <Pine.GSO.4.10.10002180741180.25236-100000 at sundial>,
  Moshe Zadka <mzadka at geocities.com> wrote:
> 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.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list