[Edu-sig] Python Pedagogy

Gregor Lingl glingl at aon.at
Fri Jul 21 20:03:03 CEST 2006



kirby urner schrieb:
> Although we all agree to use 'self' as the "me object" proxy, it's not
> a keyword, and we could use a different stand in, e.g.:
> 
> class Human (object):
> 
>     def __init__(me, name):
>         me.name = name
> 
>     def __repr__(me):
>         return 'Hi, my name is %s' % me.name
> 
>>>>  import subgenius
>>>>  aguy = Human('Bob')
>>>>  aguy
> 'Hi, my name is Bob'
> 
...
> Likewise, I think when coming to think formally in terms of objects
> (vs. informally, which begins with the emergence of language), it
> helps to personally project a "self" into various household objects,
> houses themselves.
> 
...
I find this a very interesting discussion (and was really puzzled by 
Andre's high-level joke in his last posting).

I'd like to supply a paradox counter point of view (perhaps just to
participate in the game). And please forgive me, that I once again use 
my turtles (objects of the Pen-class) in my examples. (They fit into the 
antropomorphic approach, anyway.)

Non - OO, teaching 'the' turtle (logo-slang) to draw a square goes like 
this:

def square(l):
     for i in range(4):
         fd(l)
         lt(90)

As soon as you want to teach to more than one turtle how 'to square'
you have to name them and treat them as objects.

Simple idea:

alex = Pen()
bert = Pen()

def alex_square(l).
     for i in range(4):
         alex.fd(l)
         alex.lt(l)

def bert_square(l).
     for i in range(4):
         bert.fd(l)
         bert.lt(l)

A bit stupid, especially if for instance there comes

chris = Pen()

So why not supply an extra argument to determine, which turtle should
'square':

def square(turtle, l):
     for i in range(4):
         turtle.fd(l)
         turtle.lt(l)

which allow us to say:

square(alex, l)
square(bert, l)

Now a simple trick comes in ...

class Turtle(Pen):
     def square(turtle, l):
         for i in range(4):
             turtle.fd(l)
             turtle.lt(l)

and we immediately better educated turtles

alex = Turtle()
bert = Turtle()
chris =Turtle()

for turtle in alex, bert, chris:
     turtle.square(l)

Hmm..., so - this my paradox 'proposition' - why not use
ClassName.lower() as replacement for self.

> 
> I''m thinking the word 'self', at least in English, is too '3rd person'
> in some ways, and looking down on a lot of objects, each with a
> 'self', you have only a god's eye view.  However, the grammar around
> 'me' is different -- there's only one of them (one first person), and
> therefore thinking "me" promotes a kind of first person instrospective
> attitude.  And we *want* that, as an option, when modeling in OO.
> 

For instance

class Human (object):

     def __init__(human, name):
         human.name = name

     def __repr__(human):
         return 'Hi, my name is %s' % human.name

so expressing, that the first parameter just names that
special instance of the class, which is meant in the
current context.

Insisting on this, I'd to add, that 'self' is not enough '3rd person',
which I don't do. I just wanted to add an additional point of view.

I write this not only for fun, but I've made the experience
(with students as well with teachers) that this approach also
can enhance their understanding of the *mechanisms* of OOP.
(altough not, perhaps, their ability to do object oriented design).

Regards,
Gregor





More information about the Edu-sig mailing list