[Edu-sig] spinning 'self'
John Zelle
john.zelle at wartburg.edu
Tue Aug 14 16:14:03 CEST 2007
On Monday 13 August 2007 11:30 pm, kirby urner wrote:
> On 8/13/07, John Zelle <john.zelle at wartburg.edu> wrote:
> > I would quibble about self not doing any work (you need it to access its
> > attributes), but I understand the point you are making. Again, though
> > this makes things seem a bit more mysterious than they really are. The
> > self parameter is a placeholder in the exact same sense that all formal
> > parameters are place holders for objects that are provided at call time.
> > The self parameter has no 'specialness' in this regard.
>
> Yes, I agree. What's special about 'self' is simply what you mentioned
> above: it gets passed "silently" and you need take special care to have
> a variable (usually 'self') ready for it as the first parameter of your
> method definition -- but then don't mention it when you call in (' self '
> is "implied" -- what makes it special).
>
But this is exactly my point. Self is _not_ passed silently. The actual
parameter is right there in the call: obj.someMethod(actual1, actual2). obj
_is_ the parameter. The only difference is that it's not inside the parens
when the call is made (unless you use someClass.someMethod(obj, actual1,
actual2, which makes my point even more directly). Self in the method
definition is not at all special. Rather it's the calling syntax that's
different. And the simplest explanation for the different form of call
syntax the fact that it's dispatching a method based on the type of obj
(although I wouldn't use that terminology for beginning students).
> But the purpose of 'self' comes into its own when you have a million
> 'selves' (or just ten) all instantiated from the very same class
> definition.
> Then we start to appreciate how each of those million has its own
> state, its own anchor in memory, thanks to 'self' (or whatever) and in
> turn self.__dict__.
OK, so objects have state. That's an important part of OO, but again, I don't
see any particular tie to the "magic" of self. Perhaps I'm reading too much
into what you are saying, but it seems like you are somehow trying to tie OO
into some "deep" truth or grand insight into the notion of self, perhaps in
the sense of self-reference and self-knowledge. At least that's what your
musing on the different points of view presented by renaming self seem to
suggest to me. I would emphasize quite the opposite: The _mechanisms_ of OO
are quite straightforward, mundane actually, and not at all amazing or
mysterious.
Again, I might just be reading too much into what you are saying, as I
personally have always been fascinated with the human sense of self (The
mind's "I" as Hofstadter and Dennet put it). Having just read Hofstader's "I
am a Strange Loop," I find myself thinking about these issues perhaps a bit
too much.
> There's nothing much else to distinguish two objects of the same type.
> ' self ' objectifies objects, and as such isn't really called upon to play
> its role until an object is instantiated (i.e. gains a self).
>
> I forgot to suggest 'I' (capital 'eye') as an interim possibility (in
> addition to candidates ' this ', ' ghost ', ' me ') though of course that's
> hard to decipher in ASCII (looks just like Number One).
Hofstadter and others point out that there is some strange entanglement or
loop going on when we use the terms like "I" or "me." That's the kind of
conundrum I'd like not to have my students thinking is part of OO. Again, the
mechanisms of OO are quite pedestrian, even though we _can_ use them to build
amazing abstraction. I say leave contemplation of "self" to philosophy and AI
classes. For me, Python's self is just the conventional name of the first
formal parameter of a method. Using the same name all the time allows anyone
reading even the smallest snippet of my code to know that I am accessing an
attribute of the object that caused the method lookup. There is nothing deep,
mysterious, magical, or even difficult, about it. Let's not give the
impression that there is.
--John
--
John M. Zelle, Ph.D. Wartburg College
Professor of Computer Science Waverly, IA
john.zelle at wartburg.edu (319) 352-8360
More information about the Edu-sig
mailing list