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.run(__dtest)\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

AJAX Joy

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

Back!

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

Progress...

...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: http://crunchy.python-hosting.com/wiki/WalkThroughs.

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