Python misconceptions in IBM Ruby article...

Bijan Parsia bparsia at email.unc.edu
Fri Feb 18 07:35:41 EST 2000


Grant Edwards <nobody at nowhere.nohow> wrote:

> John Farrell <jfarrell at mincom.com> 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.
> 
> > * 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.
> 
> The use of the 'self' parameter in methods is something that
> both Modula-3 and Smalltalk do (IIRC -- it's been a few years).

To be pedantic (and in the Python group, when writing about Smalltalk,
I'm *always* pedantic :)), in Smalltalk, each class has direct access to
it's instance variables. Indeed, that's how you implement accessors:

        Foo>>getName
                ^name
             setName: anObject
                name := anObject

(the caret means return, and no self-respecting Smalltalker would use
the selectors #getName and #setName: over #name and #name: ;))

Now, in order to preserve the uniformity of message sending syntax
(i.e., that all computation is invoked by sending a message to an object
using the Object message pattern) there is a psuedo-variable (#self)
which refers to the instance "possessing" the method.

        Foo>>returnNameUppercased
                ^self name asUppercase

self can't be assigned to, nor, I believe, can you assign it using the
assignment operator (although you can pass it as the argument of a
message; which is very handy). That's why it's "psuedo". #super works
similarly.

> I think it results in much more readable code.  While OO may be
> an 'add-on' in the case of M3, I hardly think that you can
> claim OO is an 'add-on' to Smalltalk.

#self, in Smalltalk, is a keyword (and I'm pretty sure #super is the
only other...nope, sorry, there's five total; true and false get in
there, I think; ack, it's too early in the morning!) whereas in Python,
I believe the *name* 'self' is simply a matter of convention (though a
rather important convention). What counts for a method is that the first
(typically implicitly passed) argument is the relevant instance.

[snip] 
> > * Proper OO languages do not use white space to delimit blocks,
> >   and use semicolons and block delimiters.
> 
> Proper languages put semicolons _between_ statements not at the
> end of statements.

My eyes bulged out at *least* a quarter inch while reading this until I
realized that 'proper' was being used as a synonym for 'prissy'. :)

Cheers,
Bijan Parsia.



More information about the Python-list mailing list