A long time ago, Kirby suggested to me (on this list I believe - I can't trace the post right now) that perhaps I should use rur-ple's code itself as an example to use. I replied that it was most likely too complicated .... but I kept his idea at the back of my mind. After seeing his post on the Monkey class, I thought of how I would go about to introduce classes, to users of rur-ple that have already written simple programs to make a robot (Reeborg) move in his world, both using the "function" notation and the OOP notation. Here are my thoughts at the moment. (Sorry for the amount of code; it is designed to be all cut-and-pasted in one chunk to be run altogether as an example. In a classroom situation it would be broken up in various steps.) The next step would be to introduce the second dimension (streets). Any kind of comments would be appreciated, especially as I am thinking of writing a rur-ple lesson using this approach :-) André ==================== # Minimal robot that can move. class Robot(object): def move(self): print "I moved." Reeborg = Robot() Reeborg.move() print "----------------" # Add real movement along a line class Robot(object): def __init__(self): self.avenue = 1 def move(self): self.avenue += 1 print "I moved to Avenue %d"%self.avenue Reeborg = Robot() Reeborg.move() Reeborg.move() print "----------------" # Add movement in both directions along the line class Robot(object): def __init__(self): self.avenue = 1 self.step = 1 def move(self): self.avenue += self.step print "I moved to Avenue %d"%self.avenue def turn_around(self): self.step = -self.step print "I turned around." Reeborg = Robot() Reeborg.move() Reeborg.move() Reeborg.turn_around() Reeborg.move() print "----------------" # Add obstacles (walls) class Robot(object): def __init__(self): self.avenue = 1 self.step = 1 self.walls = [0, 5] def move(self): self.avenue += self.step if self.avenue in self.walls: print "A wall is preventing me to move to Avenue %d"%self.avenue self.avenue -= self.step else: print "I moved to Avenue %d"%self.avenue def turn_around(self): self.step = -self.step print "I turned around." Reeborg = Robot() Reeborg.move() Reeborg.move() Reeborg.turn_around() Reeborg.move() Reeborg.move() Reeborg.move() Reeborg.turn_around() for i in range(5): Reeborg.move() print "----------------" # Create world and robot separately; put robot in world class World(object): def __init__(self): self.walls = [] def add_wall(self, avenue): self.walls.append(avenue) def is_clear(self, avenue): return avenue in self.walls class Robot(object): def __init__(self, world): self.avenue = 1 self.step = 1 self.world = world def move(self): self.avenue += self.step if self.world.is_clear(self.avenue): print "Something in the world is preventing me", print "to move to Avenue %d"%self.avenue self.avenue -= self.step else: print "I moved to Avenue %d"%self.avenue def turn_around(self): self.step = -self.step print "I turned around." w = World() w.add_wall(0) w.add_wall(5) Reeborg = Robot(w) Reeborg.move() Reeborg.move() Reeborg.move() Reeborg.turn_around() Reeborg.move() Reeborg.move() Reeborg.move() Reeborg.move() w.add_wall(3) Reeborg.turn_around() for i in range(3): Reeborg.move() print "----------------"
Any kind of comments would be appreciated, especially as I am thinking of writing a rur-ple lesson using this approach :-) André ====================
I really like this kind of thing André. One thing I like is the visual imagination is engaged (avenues, obstacles) and yet the code and evaluation loop are entirely lexical. This is more like reading a book (without pictures even), which is what children are learning to appreciate (we hope): scanning typography while using their imaginations at the same time. Those of us heavily into TV as a medium don't want to lose or undermine that skill. The fact that you actually *do* move to visual animations later, using the facilities of wx, is very good as well. Switching between modes is valid, and we're dealing with TV generations who hunger for more visual stimuli. I often think education is a travesty because we build visual literacy through television and then set up our classrooms to fight or ignore that literacy, going only for chalk boards and slow talking. Switching between modes is key. It restores faith among students that we recognize all their modes / talents and plan to reinforce across the spectrum. Cartoons are not evil, but neither is reading and imagining (with few if any visual aids). In sum, I think it's OK to teach the traditional read/imagine mode ONLY IF we acknowledge and respect the TV and audio modes they've learned from multi-media. I am very much in favor of teaching multi-track editing as a part of regular schooling (lots about this in my blogs). More to the details of your code: a technique I use sometimes is to start with a simple Monkey (or let's say Robot in this case) and evolve it through subclassing. In other words, as I add new capabilities, I don't show a more and more complicated Robot. Rather, I show more and more descendents, in an inheritance chain, each generation adding to and/or modifying the behavior of ancestor robots. There's an implicit message here, that the children may be more capable than the adults. That reflects my belief system: that humans are still on a learning curve and our children *are* more generally adapted and competent to live in the future than we are, in the natural course of things. That doesn't mean they should disrespect us (we have much more experience). It does mean we should eagerly share power. Too much talk today, on adult math teacher lists, is about how "the kids today" are dumber and/or less qualified than we were or are. This is all a prelude / setup for not turning over significant responsibility to younger people. Because our traditional school system has not made sophisticated use of TV or multimedia (which young people grew up on), I tend to side with them and make it part of my business to boost their power and authority, in part by taking their talents and powers seriously. Related blog post: http://controlroom.blogspot.com/2006/02/boosting-bandwidth.html Kirby
On 3/4/06, kirby urner <kirby.urner@gmail.com> wrote:
I really like this kind of thing André.
:-)
One thing I like is the visual imagination is engaged (avenues, obstacles) and yet the code and evaluation loop are entirely lexical. This is more like reading a book (without pictures even), which is what children are learning to appreciate (we hope): scanning typography while using their imaginations at the same time. Those of us heavily into TV as a medium don't want to lose or undermine that skill.
The fact that you actually *do* move to visual animations later, using the facilities of wx, is very good as well. Switching between modes is valid, and we're dealing with TV generations who hunger for more visual stimuli. I often think education is a travesty because we build visual literacy through television and then set up our classrooms to fight or ignore that literacy, going only for chalk boards and slow talking.
Actually, it's the other way around. I start *within rur-ple* with the simplest program. move() turn_off() The student gets the visual feedback right way. Then, within rur-ple, I introduce Python's syntax, building more and more complex programs. Then I introduce OOP notation: Reeborg = UsedRobot() Reeborg.move() It is after this step that I was planning to introduce the class example I gave, to show students how they could design their own robot. [snip]
More to the details of your code: a technique I use sometimes is to start with a simple Monkey (or let's say Robot in this case) and evolve it through subclassing. In other words, as I add new capabilities, I don't show a more and more complicated Robot. Rather, I show more and more descendents, in an inheritance chain, each generation adding to and/or modifying the behavior of ancestor robots.
Since I want the students to design their own robot, I thought of emulating the inheritance that they had seen. The UsedRobot() objects can only turn left. RefurbishedRobot() can turn right, and inherits from UsedRobot. So, I thought of building Robot() until it had the same abilities as rur-ple's UsedRobot(). Then, introduce subclassing to build a BetterRobot() that would have the same abilities as rur-ple's RefurbishedRobot(). André
-----Original Message----- From: edu-sig-bounces@python.org [mailto:edu-sig-bounces@python.org] On Behalf Of kirby urner Sent: Saturday, March 04, 2006 9:18 AM To: Andre Roberge Cc: edu-sig@python.org Subject: Re: [Edu-sig] Introducing classes
Any kind of comments would be appreciated, especially as I am thinking of writing a rur-ple lesson using this approach :-) André ====================
In sum, I think it's OK to teach the traditional read/imagine mode ONLY IF we acknowledge and respect the TV and audio modes they've learned from multi-media. I am very much in favor of teaching multi-track editing as a part of regular schooling (lots about this in my blogs).
The difference in our sensitivities here has to do with the fact that I am unwilling to forget that the media our kids are experiencing is as it is only as a matter of market forces. The classroom should be a haven, and a respite and a counterforce. And one way to communicate to kids that we are somewhere else, is to turn off the TV. Art
The difference in our sensitivities here has to do with the fact that I am unwilling to forget that the media our kids are experiencing is as it is only as a matter of market forces. The classroom should be a haven, and a respite and a counterforce. And one way to communicate to kids that we are somewhere else, is to turn off the TV.
Art
From my point of view, economics doesn't stop at the school house even
We should distinguish between TV as a medium for communication, and the programming (content). With free Google video streaming etc., more affordable equipment, it's ever more feasible for kids to author their own media, which is what my earlier cited blog post was in part about. And you could get educational videos other than via commerical broadcast or even cable. Yes, these cost money to produce, but so do text books. pre-TV. This idea of a "haven" seems ultra-naive. Those text book companies have a bottom line to think about, plus economic needs have always shaped what gets taught (or *not* taught as the case may be). I worked at McGraw-Hill in the 1980s. I'm not entirely clueless about these things. I think TV as a medium is what kids need fluency in, as creators, not just passive consumers. Watch what others have done with an eye towards doing your own. Same as in music, other media. I think to NOT make this medium a part of schooling is part of the cultural and generational breakdown that's happening around school. Kids get brought up on TV from a very young age, develop their brains around it, but then are expected to go cold turkey with when it comes to formal education. That's really screwed up. It's not a haven we create, but a bandwidth starvation zone. Kirby
-----Original Message----- From: edu-sig-bounces@python.org [mailto:edu-sig-bounces@python.org] On Behalf Of kirby urner
With free Google video streaming etc., more affordable equipment, it's ever more feasible for kids to author their own media, which is what my earlier cited blog post was in part about.
Having a son who has surprised me with his interest and aptitude in doing this kind of thing - I can't completely disagree. One thing he showed me was something he did taking stills of him and his friends and setting them to music - a rap song. Without going into details - it was very funny and well executed. Off-color - and something he did for his and his friends' amusement, not for school. I didn't ask too many questions, but my impression was that the tool he used was a blackmarket copy of Final Cut Pro. Because that I guess is what he was taught to use, and obviously a student cannot hope to have access to a legal copy. So I will not fight you - with the proviso that the kids are not being taught to use expensive proprietary tools. Hopefully stimulating the imagination does not need to include stimulating the criminal mind ;) Art
On 3/4/06, kirby urner <kirby.urner@gmail.com> wrote: [snip]
Too much talk today, on adult math teacher lists, is about how "the kids today" are dumber and/or less qualified than we were or are. This is all a prelude / setup for not turning over significant responsibility to younger people.
Because our traditional school system has not made sophisticated use of TV or multimedia (which young people grew up on), I tend to side with them and make it part of my business to boost their power and authority, in part by taking their talents and powers seriously.
Related blog post: http://controlroom.blogspot.com/2006/02/boosting-bandwidth.html
I agree that the education system could make a better use of modern multimedia tools ... but up to a point. A teacher should *not* have to be an entertainer first. A teacher should be a guide for learners, accompanying them in their journey. The goal of the journey might be for the learners to become their own entertainer, producing "stuff" that interest them - within the discipline being considered. This may mean having them use Python and related tools (e.g. PyGeo) to learn about mathematical concepts. *But*, it means having *them* (the learners) using Python and related and non-related tools. That's where I differ from some points you made in the above quoted blog entry. If all teachers shared your skills, perhaps I might come to a different conclusion. However, they do not ... and this is partly why I've argued to see more discussions about things like turtle.py - how it can be used in a teaching setting, simple examples, pedagogical guides, enhancements, etc. Something that can help your average teacher be a respected guide from what s/he can bring to their learners. André
Kirby
Hello All, I need to get up to speed on wxPython and was wondering if you could recommend the best resources for the task. Thanks! PS - When Mark Hammond's Windows stuff came out for 2.4, it became clear that the COM stuff was buggy. Does anyone know if that has been fixed? Thanks again. -- Best regards, Chuck
On 3/4/06, Chuck Allison <chuck@freshsources.com> wrote:
Hello All,
I need to get up to speed on wxPython and was wondering if you could recommend the best resources for the task. Thanks!
Perhaps not as your first step, but I would highly recommend that you have a look at the wxPython demo. I almost always look at it first when I want to learn to do something using wxPython. It requires a separate download. There's a new book that will be coming out soon which I definitely intend to buy: http://www.manning.com/books/rappin The cost of shipping to Canada is such that I will wait for it to be available through other channels (Chapter's or Amazon). However, from the link above, you can buy an e-book, which has about half the chapters available (it looks like the whole thing will be available within a month). I have heard great things about this book from wxPython users whose opinion I highly respect. Another path may be to use Dabo, which includes a wrapper around wxPython, and is supposed to be easier to learn. I've heard good things about it, but never tried it myself. André
PS - When Mark Hammond's Windows stuff came out for 2.4, it became clear that the COM stuff was buggy. Does anyone know if that has been fixed? Thanks again.
-- Best regards, Chuck
There's a new book that will be coming out soon which I definitely intend to buy: http://www.manning.com/books/rappin The cost of shipping to Canada is such that I will wait for it to be available through other channels (Chapter's or Amazon). However, from the link above, you can buy an e-book, which has about half the chapters available (it looks like the whole thing will be available within a month). Most of it is already available, with the whole book due quite soon. By the way, if you buy the e-book from them, you can later use the e-book purchase price as credit towards the purchase of the paper book
Andre Roberge wrote: directly from them (which will be at full retail price). --Scott David Daniels Scott.Daniels@Acm.Org
Hello Andre, Thanks. I'll get the e-book from manning right now. Saturday, March 4, 2006, 10:19:12 AM, you wrote: AR> On 3/4/06, Chuck Allison <chuck@freshsources.com> wrote:
Hello All,
I need to get up to speed on wxPython and was wondering if you could recommend the best resources for the task. Thanks!
AR> Perhaps not as your first step, but I would highly recommend that you AR> have a look at the wxPython demo. I almost always look at it first AR> when I want to learn to do something using wxPython. It requires a AR> separate download. AR> There's a new book that will be coming out soon which I definitely AR> intend to buy: AR> http://www.manning.com/books/rappin AR> The cost of shipping to Canada is such that I will wait for it to be AR> available through other channels (Chapter's or Amazon). However, from AR> the link above, you can buy an e-book, which has about half the AR> chapters available (it looks like the whole thing will be available AR> within a month). I have heard great things about this book from AR> wxPython users whose opinion I highly respect. AR> Another path may be to use Dabo, which includes a wrapper around AR> wxPython, and is supposed to be easier to learn. I've heard good AR> things about it, but never tried it myself. -- Best regards, Chuck
-----Original Message----- From: edu-sig-bounces+ajsiegel=optonline.net@python.org [mailto:edu-sig-bounces+ajsiegel=optonline.net@python.org] On Behalf Of Andre Roberge
A long time ago, Kirby suggested to me (on this list I believe - I can't trace the post right now) that perhaps I should use rur-ple's code itself as an example to use.
If it is appropriate to talk about our projects and where we are with them and what is driving are efforts, as I think it surely well should be: This resonates highly with how I have spent a good deal of my free time the last month. Among my follies with PyGeo is trying to bring some life and reality to the concept that the code is its text - both in terms of tying together programming and functionality, and in tying together analytic mathematics with geometry and the sensible world. Part of the problem there is of course making one's code worthy. Not sure I can ever solve that with full satisfaction - but starting from little things, I don't think you will be able to find a line in PyGeo anymore - far from where it was - that is not orthodox in terms of something as simple and 'unessential' as indentation. In the end, there is no excuse for PyGeo to *be* in Python (better performance could be achieved elsewhere) if the readability and access to the code is not part of its intent. So maybe my thinking hear is some form of rationalization of the fact that it is. And where it has led me recently is on a journey connected to automated documentation, having become enamored by what the Pudge documentation project is trying to do - essentially auto generating context sensitive hyperlinks between reStructured text doc strings and nicely colorized html versions of the source code. But the project is young, doesn't work for me as I ultimately would like to see it. That is without me getting hand-on with it. So it has led me into the netherworld of the docutils state machine, the inspect module, Kid XML templating. It's all hard for me to keep up with - but that's how I learned to ski, following folks down the mountain who know what the hell they were doing, and trying to keep up. Pudge cite: http://pudge.lesscode.org/ The end. Art
On 3/4/06, Arthur <ajsiegel@optonline.net> wrote:
-----Original Message----- On Behalf Of Andre Roberge
A long time ago, Kirby suggested to me (on this list I believe - I can't trace the post right now) that perhaps I should use rur-ple's code itself as an example to use.
If it is appropriate to talk about our projects and where we are with them and what is driving are efforts, as I think it surely well should be:
Personally, I find it motivating to hear about other people's "behind the scene thoughts" about their programming projects.
This resonates highly with how I have spent a good deal of my free time the last month. Among my follies with PyGeo is trying to bring some life and reality to the concept that the code is its text - both in terms of tying together programming and functionality, and in tying together analytic mathematics with geometry and the sensible world.
This is very reminescent of Knuth's literate programming concept. I'd be curious to see what you think of Leo, the Python based outliner/editor. I don't use it myself, as I find it to be too much of a barrier between my brain and my code ;-)
Part of the problem there is of course making one's code worthy. Not sure I can ever solve that with full satisfaction - but starting from little things, I don't think you will be able to find a line in PyGeo anymore - far from where it was - that is not orthodox in terms of something as simple and 'unessential' as indentation.
You made me curious, and I had to see what you meant. I only looked at the vpyframe.py file. I think I understand one thing: you use "inconsistent" indentation (mostly 3 spaces, a few times 4 spaces or 5 spaces. Python, being Python, makes the structure of your code understandable. However, as I use indentation guides set at 4 spaces in my editor, your indentation choices make it a bit more difficult for _me_ to read. [snip]
And where it has led me recently is on a journey connected to automated documentation, having become enamored by what the Pudge documentation project is trying to do - essentially auto generating context sensitive hyperlinks between reStructured text doc strings and nicely colorized html versions of the source code.
[snip]
Pudge cite:
Thanks for the link. André
Andre Roberge wrote:
... I thought of how I would go about to introduce classes, to users of rur-ple that have already written simple programs to make a robot (Reeborg) move in his world, both using the "function" notation and the OOP notation.
... Hi Andre and all of you, may I give you a short sketch of my approach to this problem, just as a supplement to your approach. It mainly deals with the transition from writing functions to writing (classes and) methods and understanding the role of the self parameter: You surely will not be surprised, that I do it with turtles. For your convenience with standard turtle.py ;-) Say, my students have written a short function
def polystep(length, angle): forward(length) left(angle)
to make the (anonymous) turtle (more exactly: Pen) draw spirals like
for l in range(4,80,4): polystep(l, 90)
Sometimes we say, we have taught the turtle a new word: polystep. So she now knows how to polystep. Say, my students then have learned to use turtle objects:
joe=Pen() ann=Pen() ann.left(180) for turtle in joe, ann: turtle.up() turtle.forward(100) turtle.down()
Wie now have two turtles at different positions on the screen. Now we want joe and ann to draw a spiral. We can do that this way:
for l in range(4,80,4): for turtle in joe, ann: turtle.forward(l) turtle.left(90)
We would appreciate it, if joe and ann both knew how to polystep:
for l in range(4,80,4): for turtle in joe, ann: turtle.polystep(l,90)
So - as a first step towards our goal - we want to modify polystep in order to pass a turtle object to it. This way it would know which turtle should perform the polystep:
def polystep(turtle, length, angle): turtle.forward(length) turtle.left(angle)
Now we can make our spirals like this:
for l in range(4,80,4): for turtle in joe, ann: polystep(turtle,l,90)
We would prefer the last line to be: turtle.polystep(l,90) i. e., that our turtles undertand how to polystep. So we make a new class, (I omit some necessary explanations here which you easily can fill in)
class MyPen(Pen): pass
which we can immediately investigate, e.g.:
joe = MyPen() ann = MyPen() joe.color("red") joe.forward(50) ann.left(90) ann.forward(50)
So we see, that MyPens (i.e. MyPen instances) know everything Pens know. MyPen is a subclass of Pen:
isinstance(joe, MyPen) True isinstance(joe,Pen) True
Every MyPen is a Pen Now we want MyPens to know more thatn Pens. So we have to teach them something new: we make polystep a method of MyPen. (The students know methods, e.g. forward as a method of Pen):
class MyPen(Pen): def polystep(turtle, length, angle): turtle.forward(length) turtle.left(angle)
We now can observe, that we have achieved, what we wanted:
joe = MyPen() ann = MyPen() ann.left(180) for turtle in joe, ann: turtle.up() turtle.forward(100) turtle.down()
for l in range(4,80,4): for turtle in joe, ann: turtle.polystep(l,90)
works as desired. We now have to explain, why there are only two arguments in the call of polystep. Lets try (arbitrary) three:
joe.polystep(1,2,3) Traceback (most recent call last): File "<pyshell#49>", line 1, in ? joe.polystep(1,2,3) TypeError: polystep() takes exactly 3 arguments (4 given)
This shows, what the Pythoninterpreter thinks about this call. He counts joe as a fourth argument. So
joe.polystep(50, 90) in fact has passed three arguments to the polystep method of MyPen, joe beeing passed to the first one, turtle. Really? Really! It does the same as: MyPen.polystep(joe, 50, 90)
That means, that the interpreter passes the turtle it*self* (for which the method is called) to the first parameter of the method. Taking into account, that one may chose variable names freely, but should chose them so, that the names appropriately describe the meaning, we replace the name turtle by the name self (and explain that that is a convention in Python):
class MyPen(Pen): def polystep(self, length, angle): self.forward(length) self.left(angle)
This last step changes nothing, except (hopefully) enhancing our understanding of the process of moving on from defining functions to defining methods, and especially of the role of self. Regards, Gregor -- Gregor Lingl Reisnerstrasse 3/19 A-1030 Wien Telefon: +43 1 713 33 98 Mobil: +43 664 140 35 27 Website: python4kids.net
participants (6)
-
Andre Roberge -
Arthur -
Chuck Allison -
Gregor Lingl -
kirby urner -
Scott David Daniels