On Sat, Nov 20, 2010 at 10:13 AM, kirby urner <kirby.urner@...> wrote:
Here's from my classroom just today (yes, on a Saturday).
The template / blueprint is for "any snake" but once we give
birth to a snake, it has a self, symbolized by the word "me"
in the code below:
class Snake:
# birth (constructor)
def __init__(me, name):
me.name = name
me.__stomach = []
def eat(me, food):
me.__stomach.append(food)
def poop(me):
if len(me.__stomach)>0:
return me.__stomach.pop(0)
else:
me._shed()
def _shed(me):
print "Shedding skin"
def show(me):
return me.__stomach
def __repr__(me):
return "I am a snake named " + me.name
In the interactive shell, using the code above:
>>> from classes2 import Snake
>>> s = Snake("Joe")
>>> s.eat("Mouse!")
>>> s.show()
['Mouse!']
>>> s.poop()
'Mouse!'
>>> s.poop()
Shedding skin
>>>
My student was 12 years old (this is one-on-one training).
He has already studied some Java, so even though this
was only our second meeting, he was ready to program
a Snake class.
His mom comes along (a former hospice nurse and
plane crash victim). We like to share odd cartoons,
Youtubes, as a way of entertaining one another.
I showed the following, because it's somewhat topical
in showing the name -> object model (which is
actually quite appropriate for Python) and because
it's so Anglo (like those picture books children learn
to read from):
http://www.youtube.com/watch?v=u1Dxn3VWOws
Kirby
PS: For more debate on whether we should yak about a
verboten "4D tetrahedron" in any math class, see:
http://groups.yahoo.com/group/synergeo/message/63625
(it's a debate that's been happening for years, leaving a
long audit trail).
People use different symbols for these computations. In Python,
we have 'self' for the "person" or "homunculus" in each object,
whereas Java has a "this". This "self" is not a key word however.
You could also say "I" or "me" and get away with it. The same
blueprint (for the type) generates "many mes" (many instances
of selfhood). You can see where object oriented thinking might
resonate with ordinary thinking -- you don't need to think about
computer internals per se. Sure, we talk about "memory" a lot,
but we have that anyway, like in cemeteries (a kind of namespace).
Here's from my classroom just today (yes, on a Saturday).
The template / blueprint is for "any snake" but once we give
birth to a snake, it has a self, symbolized by the word "me"
in the code below:
class Snake:
# birth (constructor)
def __init__(me, name):
me.name = name
me.__stomach = []
def eat(me, food):
me.__stomach.append(food)
def poop(me):
if len(me.__stomach)>0:
return me.__stomach.pop(0)
else:
me._shed()
def _shed(me):
print "Shedding skin"
def show(me):
return me.__stomach
def __repr__(me):
return "I am a snake named " + me.name
In the interactive shell, using the code above:
>>> from classes2 import Snake
>>> s = Snake("Joe")
>>> s.eat("Mouse!")
>>> s.show()
['Mouse!']
>>> s.poop()
'Mouse!'
>>> s.poop()
Shedding skin
>>>
My student was 12 years old (this is one-on-one training).
He has already studied some Java, so even though this
was only our second meeting, he was ready to program
a Snake class.
His mom comes along (a former hospice nurse and
plane crash victim). We like to share odd cartoons,
Youtubes, as a way of entertaining one another.
I showed the following, because it's somewhat topical
in showing the name -> object model (which is
actually quite appropriate for Python) and because
it's so Anglo (like those picture books children learn
to read from):
http://www.youtube.com/watch?v=u1Dxn3VWOws
Kirby
PS: For more debate on whether we should yak about a
verboten "4D tetrahedron" in any math class, see:
http://groups.yahoo.com/group/synergeo/message/63625
(it's a debate that's been happening for years, leaving a
long audit trail).