[Edu-sig] Python Pedagogy

kirby urner kirby.urner at gmail.com
Fri Jul 21 17:45:09 CEST 2006


On 7/21/06, Andre Roberge <andre.roberge at gmail.com> wrote:

> The "me" approach is very anthropomorphic and may not work well in all
> languages.   Mind you, the same is true for "self".
>

Yes, deliberately anthropomorphic, put less about turning things into
people than people into things, as a skill associated with modeling
("I am hydroelectric dam"  "I am an airplane" -- what are my behaviors
and states?).

> Python creates a new instance of the class RepairedRobot and defines
> all the methods, replacing the first argument of the method
> (synonym_used_to_refer_to_this_object) by the name of the instance
> (newReeborg).

I like your linking of the named instance to 'self' internally.  That
fits with the "point of view" approach where we say:  I am "that
human" to other humans, but internally I am simply me or self.

The class blueprint allows for every Human to have a self, and this is
built in to the code in advance of creating any named instances.
Likewise for other objects (we can talk about selfless classes another
time).

It's also important to distinguish the variable dog1 from dog1's
attributes, one of which may be a proper name such as 'Rover' (a
string).  Even if we write rover = Dog('rover'), it's best to think of
the passed-in string 'rover' as something etched on rover's collar,
rather than as rover-the-dog.

Note that rover.self raises an exception.  self is not an 'attribute'
of an object but a way for code to gain a reference to the specific
instance "from within".  This instance is perhaps best conceptualized
as a discrete chunk of memory somewhere (something to be garbage
collected when no longer referenced externally).

All this resonance with ordinary concepts (self, introspection) is
*not* something to fight ("oh, you shouldn't think this means anything
like what you're used to") but to embrace and work with ("yes, the way
you already think is going to help you master OO).

Kirby


More information about the Edu-sig mailing list