Saturday, July 8, 2006

Lights and Sound

Among quite a few small things that I've been working on over the last week, I've added `proof of concept` Sound Synthesizer and some fancier formatting to the output.

The sound synthesizer has no dependencies outside of the Python built-in library modules (wave, ossaudiodev and winsound) and should be completely cross-platform (OK, maybe not mac-compatible :-( ), although I haven't had a chance to test it on Windows yet. Admittedly this isn't really a feature of crunchy, more a demo of what is possible with crunchy - but it should still be interesting for kids.

The formatting uses HTML in the webpage to show stdout output blue and stderr output red, which makes errors that bit more readable. The project to handle errors more gracefully has stalled somewhat because of the huge number of different ways most errors can occur - for instance SystemError - you really can't do much with it other than display the whole lot.

One problem that has become more pressing with the introduction of the SoundSynth is the way program execution blocks the interface. I'm working on a way of simulating a remote tty using AJAX which will solve both the asynchronous execution and the raw_input problems. I don't have all that much experience at threaded programming, so it's very much a learning experience for me!

Once we have integrated the graphics canvas into the normal interpreter (so that graphics commands can be called from anywhere within crunchy and they will still load) I think we'll be ready for a new release of crunchy and I will be ready to start writing tutorials.

Thursday, June 29, 2006

Say no to temporary files!

My last post mentioned the problems I was having with doctests, luckily I managed to solve them - but only after about 5 hours of frustrated playing with the API.

The problem arose because to get a DocTest object you have to know the namespace over which it is to be tested, but getting that namespace in the right place is tricky. My final solution was (I like to think) quite an inspired hack:

  1. Take the code to generate the namespace and append some code to generate and run a doctest.
  2. generate DocTestParser and DocTestRunner objects.
  3. exec the code in a namespace that has references to the DocTestParser, the DocTestRunner and a string containing the actual doctests.

The end result looks something like this:

def run_doctest(code, test):
....code = code + '\n__dtest=__parser.get_doctest(__test, globals(), "Crunchy Doctest", "crunchy", 0)\\n'
....runner = DocTestRunner()
....parser = DocTestParser()
....exec code in {'__runner':runner, '__parser':parser, '__test':test}
It's a wonderful feeling when something is suddenly so obvious!

Tuesday, June 27, 2006


Over the last two days I've been playing with HTTP POST and the xmlhttprequest object and teaching myself the HTML DOM (basically the stuff underneath AJAX, although without the AX). Crunchy now only uses HTTP GET for loading new pages and the graphics canvas (which will change as soon as I've tidied up what I've done already)

The speed improvements feel incredible  - pages no longer even pause when running most simple code.

Another change I've made is stopping code executing in temporary files, sadly I can't see how to do doctests without writing to a temporary file because we need a module to run doctest in and as far as I know, module objects are only created when a file is read.

Another welcome side effect of these changes is that it will be almost trivial to add in support for custom error reporting, we just have to subclass code.InteractiveInterpreter - isn't Python beautiful?!

I'll be posting a request for comments on simplified error reporting on the edu-sig mailing list in a couple of days once I've come up with some decent ideas.

In other news, I'm starting to doubt the viability of teaching programming to 7 year old's without recourse to an adult on hand all the time - but on the other hand Crunchy is becoming a viable platform even for more advanced students (Andrew Harrington from Loyola University seems very interested in it). I will continue to endeavour to come up with ways of making this easy enough for kids <10 years old, but I feel it would be more constructive to concentrate on an age group of >10. A tutorial that a 10 year old can understand without adult guidance should be possible for a 7 year old with an adult!

Sunday, June 25, 2006


I know it's been 3 weeks since I last posted, I've been suffering from chronic exams and revision. Now I'm finally back home and working hard again.

There has been lots of progress of crunchy - we have a Graphics Canvas (coded by Andre) using javascript and the canvas tag, Andre has squashed a whole load of bugs and added a proper error interface.

Over the next few days I will be working on a system to parse errors in student's code and present the students with simplified/more meaningful error messages. I'll also start making POST requests work in preparation for moving a lot of the functionality over to AJAX.

Wednesday, May 31, 2006


...has been slow this week - I have mocks on Thursday and Friday.

There have been lots of helpful suggestions for a graphics library varying from feature requests (The need to address individual pixels) to heavy duty discussions on the pedagogical aspects of graphics.

I started coding a library at the beginning of the week, but I have since realised that it was far too complex for a 7 year old. The Livewires API looks interesting but is aimed at 12+, maybe 7 year olds are a bit ambitious. Platform independence is another issue: Cairo is all well and good on UNIX, but it has stupid dependencies on Windows - there is a large part of me that wants to use Cairo on *NIX (it even has SVG support, imagine the possibilities!) and fall back on something less impressive for Windows. Or maybe I should create my own distribution of PyCairo for Windows that doesn't depend on GTK.

I have also just realised that sound is going to be an issue - PyGame has excellent support for playing pregenerated sound, but virtually none for synthesized sound, which was what I had envisaged. Some kind of interface to MIDI would be perfect - although maybe too much to hope for. I don't want to have to rely on pre-recorded sound, it's much less interesting.

Anyway, end of winge. There won't be another status update until Sunday at the earliest I'm afraid.

Friday, May 26, 2006

Code Explanations

I've created a page where I will put explanations of my code:

Think of the stuff here as more advanced tutorials that don't fit in with the 7-14 target age range!

Small Update

Andre found a solution to the exiting problem - I had just been setting the wrong variable!

In other news, I have registered an account with which I will be using as an SVN repository - at the moment I don't have any plans to use the wiki apart from the front page: take a look at

CherryPy is Gone!

When I posted my last missive, my version of Crunchy didn't do everything it should have - but I've now got it to a point where everything apart from exiting works (I've decided to drop support for arbitrary local tutorials for now - see below). So I can now say that CherryPy has been eliminated without any major issues.

The problem with exiting seems to be because HTTP/1.1 has persistent connections, so BaseHTTPServer.HandleRequest never actually returns (I don't really understand the intricacies of HTTP very well though - I should go and read the RFC I guess). I've given the code to Andre - maybe he can spot something to help.

I have some ideas about packaging groups of individual tutorials as "courses" - with additional metadata describing the relationships between tutorials (pages) in the course (see Andrew Harrington's post on the edu-sig list - this is what prompted the idea).

Basically, a course would be encapsulated in a directory (could also some kind of archive, say a zip file), and would have an index file that contained any metadata needed in multiple pages. The individual pages would then be referenced by the index (naturally pages could still link to each other). The index could also define some bijection from page "meta-names" to page files.

I will post my ideas on the edu-sig list once they're more mature.

Wednesday, May 24, 2006

Progress so far

I'm a naturally impatient person, so I actually started working on the project on Monday - 48 hours before I actually got confirmation I was in.

So far I've succeeded in removing the dependency on CherryPy using the BaseHTTPServer module from the Python base libraries. This was actually quite fun, because I've written a simple HTTP server in C before, but the Python version is far more elegant. Note that while I have replaced the whole server, it didn't actually mean using much more code - which really goes to show how unnecessary CherryPy is when you're doing something moderatley simple.

I am told that Elementtree is in Python 2.5, so getting rid of it isnt a priority at all (thankfully).

I've sent the code to Andre, so hopefully we'll see something like this in a release soon.


Note: this was written back in 2006 when I was about to become an SoC student, see this post for some updates on what I'm doing now.

Hi, I'm Johannes Woolard, a 19 year old student at the University of Oxford in the UK. I've just heard that I've been accepted into the Google Summer of Code scheme to work for the Python Software Foundation. I'm planning to use this blog to document my progress and experiences along the way.
Briefly, my project involves writing interactive web-based tutorials for 7-14 year olds. I'm being mentored by Andre Roberge (he has a blog too).