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.