Python misconceptions in IBM Ruby article...

John Farrell jfarrell at mincom.com
Sun Feb 20 19:09:01 EST 2000


Moshe Zadka 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.

Yes, I realise that, but when I am writing a method I have an uncomfortable
feeling that 'self' might under some circumstances be different from the
object that the method is bound to. What if I assign to 'self'? What if
I do this:

class Stuff:
    def foo(x):
        print x

a = Stuff()
Stuff.foo(a) 
Stuff.foo(4)

When I write in Java I would intend something like this to mean that
foo is a class method of Stuff. However in Python, I can't write class
methods. Whenever I invoke a method defined in a class it is interpreted
as an instance method, and Python checks to see that the first parameter
is an instance of Stuff. If that check was removed, I claim that all
code that currently works would continue to work, and methods which were
written as class methods would also work. (I am not saying that that
check SHOULD be removed.) This suggests that what Python is really giving
us is:

 * class methods, i.e. normal methods whose names look like Class.blah
   rather than just blah.
 * an automatic type check on the first parameter of a class method
 * the ability to bundle the method and its first parameter together
   to make a bound method.

Now, I do not propose that this be changed, and I do not claim that
other languages are better because of this. However I do claim that there
is a tacked-on feeling about it. I think it's a little bit disingenuous
to disparage the Ruby article for claiming that Python's OO features
feel added-on, when there is considerable evidence to support that claim.

John
-- 
Dr John Farrell - Research Architect - Mincom Limited

I don't suffer from stress.  I am a carrier.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s++:+ a C+++ U+ P-- L E--- W++ N+(-) o+ !K w---(+) !O !M !V PS+ PE Y?
PGP t--- !5 !X R(+) tv- b++ DI++ D G e++++ h---- r+++ y++++(*)
------END GEEK CODE BLOCK------
This transmission is for the intended addressee only and is confidential
information. If you have received this transmission in error, please delete
it and notify the sender. The contents of this E-mail are the opinion of the
writer only and are not endorsed by Mincom Limited unless expressly stated
otherwise.




More information about the Python-list mailing list