technology from back to front

Teaching programming, RUR-PLE, and Rurple NG

If you’ve never programmed a computer, you should. There’s nothing like it in the whole world. When you program a computer, it does exactly what you tell it to do. It’s like designing a machine — any machine, like a car, like a faucet, like a gas-hinge for a door — using math and instructions. It’s awesome in the truest sense: it can fill you with awe.

A computer is the most complicated machine you’ll ever use. It’s made of billions of micro-miniaturized transistors that can be configured to run any program you can imagine. But when you sit down at the keyboard and write a line of code, those transistors do what you tell them to.

Most of us will never build a car. Pretty much none of us will ever create an aviation system. Design a building. Lay out a city.

Those are complicated machines, those things, and they’re off-limits to the likes of you and me. But a computer is like, ten times more complicated, and it will dance to any tune you play. You can learn to write simple code in an afternoon. Start with a language like Python, which was written to give non-programmers an easier way to make the machine dance to their tune. Even if you only write code for one day, one afternoon, you have to do it. Computers can control you or they can lighten your work — if you want to be in charge of your machines, you have to learn to write code.

–Cory Doctorow, Little Brother

Partly inspired by that paragraph, this summer’s craze for me is teaching my friends to program; so far five different people have let me start them off on the basics. I don’t necessarily hope to make professional programmers or dedicated hobbyists out of them all; I have a couple of more modest goals:

  • I’d like people to experience the sense of excitement and awe that the paragraph above captures; to know for themselves why we can get lost in worlds that we build and control ourselves, and hopefully, maybe, to program for fun themselves on the occasional rainy day or more.
  • Even if they never again take up programming outside of the one lesson I give, I’d like to give people that one afternoon, an understanding of what a computer program is, to strip away some of the mystery of what it is that computers do and how they do it

I started when a friend who is doing a creative writing degree said something like “But don’t you have to learn a lot of theory before you can start to program?” I grabbed the laptop, opened an editor window and typed

print "Hello world"

“That is a complete computer program” I said. “Can you guess what it does?”

From there it was easy to move on to a succession of slightly more complicated programs, demonstrating each of the major building blocks of programming languages in turn. I’m not sure she’s going to ask for a second lesson, but I think she left the first with the feeling that what I do for a living, or where the software she uses comes from, is that bit less mysterious.

However, programs that print things on a terminal aren’t necessarily the most fun or engaging things to play with – I tried relying on that for a second, more hands-on lesson with another friend, and I think the fun vs frustration ratio left something to be desired. The usual solution to this is turtle graphics as pioneered in the programming language Logo, but I found it hard to think of any interesting programs to write with the turtle – it seems as though to get a lot out of it, you have to really like geometry, which few of us do.

Much more appealing is the grid-based world of Karel the robot. While the turtle wanders around the barren infinite plane with only its own lines for company, Karel’s world includes impassable walls aligned with the grid lines and objects called “beepers” in the grid squares that the robot can detect, pick up and put down. This makes it natural to write programs that do more than follow a predetermined sequence of steps – programs that actually discover the state of the world they find themselves in and adjust how they act appropriately.

These ideas have been picked up in other tools, most notably the teaching environment Guido van Robot. However, in common with its predecessor, these environments teach their own custom language: once a student is ready for greater things, they must start learning a new programming language. I’m no pro at these things, but I’m inclined to see this as a waste; the syntax of Python is easily simple enough for a beginner to start with right away, and I think it’s a powerful selling point and confidence booster for the student if you can honestly say that the language that they are now learning is used by choice at Google and all over the world by real programmers with real jobs to do.

So this finally led me to my favourite tool so far: RUR-PLE.

RUR-PLE: a Python learning environment

RUR-PLE is exactly this synthesis: it provides the maze-like environment of Karel and Guido van Robot, with the syntax of the real Python programming language. RUR-PLE ships with a range of pre-designed mazes for various programming challenges that introduce the key ideas of the Python programming language in a fun way, as well as a complete HTML manual for learning programming.

And it really works – people found it intuitive and rewarding to move the robot, and it was easy to come up with maze-based challenges that illustrated programming concepts. The simple integrated debugger meant that whenever it did something unexpected, it was easy to take it through step by step to see why it was doing what it did, and the robot graphics provided satisfying instant results. I knew I was doing something right when one friend practically ran back to the computer after dinner to finish debugging her maze solving application.

However, there are a few problems with RUR-PLE. The user interface is in many ways unnecessarily complicated and unintuitive. The program provides four “tabs” with four different functions that to me would be better provided as four separate applications, especially since one is a browser window with a lesson plan where most users would prefer to use the browser they normally use. There is no menu bar, so everything has to be done with buttons on the toolbar. This toolbar is written in a non-standard way that is less attractive than platform standard ways of doing these things. The robot is drawn in elevation even though the maze is seen in plan, which makes life harder for users who are already tripping up on telling their left from their right, and the squares of the grid are at right angles to the walls instead of lined up with them, just one of the unnecessary visual complications in the grid; another complication is that the Python editor is a full folding editor, useful for experienced programmers but another potential source of confusion for beginners. Users are instructed to call a “turn_off()” instruction at the end of every program, a rather unPythonic way of doing things that makes the simplest working program twice as long as it needs to be, and which turns out to be a hangover from its Karel-based roots – as is the rather confusing name of “beepers” for the objects that the robot can pick up and put down.

Since it’s in Python, I thought these problems (and others, such as that you can’t change the speed at which the program runs once it’s running) would be easy to fix, but as I started digging into the code I discovered that the structure made fixing these things hard. As I learned later, the author wrote it as part of an exercise in teaching himself Python programming, and it shows: the code is in many places more verbose than it needs to be, and the abstraction that would allow me to restructure the UI while keeping the core functions in place was absent.

So I did what one should never do: I started a complete rewrite, now called “Rurple NG” for “Next Generation”. And I’m pleased to report that so far I’m getting very nice results. There’s still a certain amount of work left to do, as the TODO file in the sources shows. But it works, and it’s good enough to use for teaching purposes now. I encourage you all to download the sources and help me hack on it or help write documentation, or simply try it and give me whatever advice you can on how this can be made better.

Rurple NG

I think most people imagine that programming is far beyond their abilities, but I believe learning to program is one of those things that nearly everyone can and should do; it’s directly beneficial even if you only ever write tiny programs to do what your existing tools can’t quite do, but it also has tremendous indirect benefits in understanding not only computers but mathematics and logic, as well as the special discipline of debugging. I hope that I can create an attractive and friendly tool that could bring programming to a new audience, and help open up our mysterious world just a little bit.

by
Paul Crowley
on
13/08/09
  1. Turtle graphics isn’t just about geometry; the turtle used to be real, and often had sensors and other effectors beyond a pen.

    That said, I normally end up teaching people fractals with turtle graphics. It’s a really nice way to instruct recursion.

    Have you considered targeting the browser instead of writing a native application?

    I have written a LOGO interpreter myself, http://logo.twentygototen.org/ but logo is kinda decrepid at times (make “x :x + 1, comes to mind), but it shows that it is possible.

    Finally: It’s worth noting that Seymour Papert’s book ‘mindstorms’ is avaliable online, via the ACM:

    http://portal.acm.org/toc.cfm?id=SERIES11430&type=series&coll=ACM&dl=ACM

    You just need a web account (no fees) to be able to download it (and a plethora of other classic books).

  2. Looks really excellent but I can’t get it to run. I get this:

    duncan@duncan-desktop:~/bin/rurple-ng-976d91193c08$ python startrurple.py
    Traceback (most recent call last):
    File “start
    rurple.py”, line 4, in
    import rurple.ui
    File “/home/duncan/bin/rurple-ng-976d91193c08/rurple/ui.py”, line 12, in
    import wx.lib.wordwrap
    ImportError: No module named wordwrap
    duncan@duncan-desktop:~/bin/rurple-ng-976d91193c08$

    This is the latest code, unzipped into a folder, on an Ubuntu Jaunty machine. Are there prerequisites?

  3. Python version requirement? On 2.5, I got:

    james-pearces-macbook-air:rurple-ng-976d91193c08 James$ python startrurple.py
    Traceback (most recent call last):
    File “start
    rurple.py”, line 4, in
    import rurple.ui
    File “/Users/James/Downloads/rurple-ng-976d91193c08/rurple/ui.py”, line 390
    e, file=self._logWindow)
    ^
    SyntaxError: invalid syntax

    Looks like a great idea though. My 6-year-old son (who wonders what the hell I do all day) will be first guinea-pig ;-)

  4. I think that this would be presented best as a Java applet. Could you run this in Jython? That way, you could let the user navigate the lesson plans via a regular web site.

  5. … yeah it works fine with Python 2.6. Cool.

  6. Yes, sorry, this requires Python 2.6 and wxpython-2.8.9.1 or later (may work with earlier, don’t know). On Ubuntu Jaunty, “sudo apt-get install python-wxtools” should ensure all requirements are met.

    The dependency on Python 2.6 is pretty central, since it requires “from future import print_function”.

  7. tef, Steve: There are several advantages to a web-based platform. Users don’t have to install anything to run the programs, it can be integrated with web-based lesson plans, and it’s easier to make cross-platform.

    However, I think there’s still room for old-fashioned applications you can install – they have a natural look and feel, they get their own place in the start menu, and stay working when you’re offline, and don’t have the distracting browser frame around them. I can get most of the advantages of lesson plan integration simply by telling the OS to use it for loading “.wld” files – then you can click on a world in the browser, and start to program it in the application.

    Anyway, I’m certainly not going to start re-coding it from scratch now – anyone who wants to write a web-based version is welcome :-)

  8. Well, I’ve already got wxpython 2.8.9.1 and python 2.6.2:

    duncan@duncan-desktop:~/bin/rurple-ng-976d91193c08$ sudo apt-get install python-wxtools
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    python-wxtools is already the newest version.

    duncan@duncan-desktop:~/bin/rurple-ng-976d91193c08$ python –version
    Python 2.6.2

    duncan@duncan-desktop:~/bin/rurple-ng-976d91193c08$ apt-cache showpkg python-wxtools
    Package: python-wxtools
    Versions:
    2.8.9.1-0ubuntu6 (/var/lib/apt/lists/gb.archive.ubuntu.comubuntudistsjauntyuniversebinary-amd64Packages) (/var/lib/dpkg/status)
    Description Language:
    File: /var/lib/apt/lists/gb.archive.ubuntu.comubuntudistsjauntyuniversebinary-amd64Packages
    MD5: 72ab7da41f88c07878ced3974d65ac14

    Reverse Depends:
    spe,python-wxtools
    python-wxgtk2.8,python-wxtools
    pyragua,python-wxtools
    model-builder,python-wxtools
    Dependencies:
    2.8.9.1-0ubuntu6 – python-wxgtk2.8 (0 (null)) wxpython2.6-0 (0 (null)) libwxgtk2.4-python (0 (null)) wxpython2.4-1 (0 (null)) wxpython2.6-0 (0 (null))
    Provides:
    2.8.9.1-0ubuntu6 –
    Reverse Provides:

    and I still get the same error:

    duncan@duncan-desktop:~/bin/rurple-ng-976d91193c08$ python startrurple.py
    Traceback (most recent call last):
    File “start
    rurple.py”, line 4, in
    import rurple.ui
    File “/home/duncan/bin/rurple-ng-976d91193c08/rurple/ui.py”, line 12, in
    import wx.lib.wordwrap
    ImportError: No module named wordwrap

    which is a shame – I’d really like to have a play with this! :)

    Any ideas?

  9. weird – that module is part of python-wxgtk2.8, which is a dependency of python-wxtools. I have the exact same version installed, and I get

    $ dpkg --search wordwrap
    python-wxgtk2.8: /usr/share/pyshared/wx-2.8-gtk2-unicode/wx/lib/wordwrap.py
    python-wxgtk2.8: /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/lib/wordwrap.py
    python-wxgtk2.8: /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/lib/wordwrap.py
    
  10. Odd. I get exactly the same output from doing ‘dpkg –search wordwrap’ as you.

    Does it matter where I’ve extracted the downloaded rurple archive? It’s extracted into ~/bin/rurple-ng-976d91193c08/ at the moment.

    • make sure that /usr/bin/python points at python 2.6

    • make sure that /usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode is in sys.path

  11. Yes, on the both counts:

    duncan@duncan-desktop:~$ file /usr/bin/python
    /usr/bin/python: symbolic link to `python2.6'

    and:

    duncan@duncan-desktop:~$ python -c"import sys;print(sys.path)"
    ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.6-gtk2-unicode', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode', '/usr/local/lib/python2.6/dist-packages']
  12. [...] das Hamster-Modell? Dann werdet Ihr auch RUR-PLE mögen. RUR-PLE ist eine Entwicklungsumgebung, die Kindern das Programmieren in Python beibringen will (Download — auch für MacOS [...]

  13. Mathematik-Schule online » Blog Archive » Daily Informatik 08/19/2009 (p.m.)
    on 19/08/09 at 12:32 pm

    [...] Teaching programming, RUR-PLE, and Rurple NG : LShift Ltd. [...]

  14. Planet Ciaran (planetciaran) 's status on Thursday, 10-Sep-09 18:14:18 BST - MicroCiaran
    on 10/09/09 at 5:15 pm

  15. Hi! being also in love with RUR-PLE I’m getting involved in the development. The merit of the application is the 48 lessons that comes with it translated in 7 languages. Code rewriting is great (and UI improvements) but if it is at the cost of making those lessons useless then the point is moot. Have you considered joining RUR-PLE and merging your code rather that doing your own?

  16. Bertrand
    on 11/04/13 at 9:32 am

    I want to use scipy with rurple , can i do “from scipy import* ” ?
    I already use scipy with python , just want to use it with ruprle.

    thx

 
 


5 − two =

2000-14 LShift Ltd, 1st Floor, Hoxton Point, 6 Rufus Street, London, N1 6PE, UK+44 (0)20 7729 7060   Contact us