Friday 9 September 2011 — This is more than 13 years old. Be careful.
I’ve been thinking about online Python learners. There have been some cool examples of online code exercises, like Nathan’s Javascript Lessons. These are great because they require absolutely no setup, and can run right on the web page that describes the concepts involved.
But of course, it’s easy to run Javascript in a browser. What are the options for doing something similar for Python?
CodingBat provides exercises for Java and Python. Your code is actually run on the server. Generally, this is risky, because Python’s dynamic nature makes it notoriously difficult to limit its powers. CodingBat does this aggressively, and manages it only because it limits the code it will run to very simple functions. For example, you cannot import anything.
Another server-side solution is the NCSS Challenge, which uses an elaborate sandboxing technique on the server to run arbitrary Python code. The sandbox is explained in this PyCon AU video by Tim Dawborn. It seems prohibitively complex, but makes it possible to run sophisticated Python code from the browser.
There are other server-side online Python execution pages:
- Python Web Console, which uses Jython (details here) so that Java sandboxing will keep the server safe.
- ScraperWiki Tutorials.
Server-side execution solve the problem of executing Python, but introduces the new problem of keeping the server safe. Can we instead execute Python in the browser? There have been some interesting implementations of this also:
- Try Python is an in-browser Python implementation using IronPython running in Silverlight. This limits its platform viability, somewhat blunting the benefits of in-browser execution. Also, most of the standard library is missing, and OS services are necessarily limited.
- Gumby is astounding: Tim Dawborn (again!) and Ben Taylor took CPython, compiled it using llvm, then ran it through an llvm-to-Javascript compiler, to produce a full implementation of CPython that runs natively in the browser. This is one of those dancing bear moments where it isn’t that it does it well, it’s amazing that it does it at all. The problems are the 790Kb Javascript download, and the limited environmental support.
- Skulpt implements Python in Javascript, from scratch, so it’s really its own Python implementation. Alone among these tools, it experiments with Python access to the browser environment, but still suffers from the in-browser problem of how to provide OS services. Also, because it’s implementing from the ground up, it’s incomplete.
Reviewing all these possibilities, none are perfect, and some are far from it. And I started to wonder, are online exercises worth all this? After all, the point of learning a language is to eventually write your own code, and that won’t happen in a sandbox in a browser. The student will have to install a real Python environment at some point, so why not start with that, and get a better learning environment right off the bat?
Are there other possibilities? Is it important? What about an environment on the student’s computer that can communicate result back to the online environment automatically? Or an online environment that can use the student’s local resources so the server doesn’t need protection?
Comments
For example, I played around with a mirror of why's online resource for Ruby, and that gave me enough to want to use it properly on my machine. I don't think I could have asked for more.
Victor Stinner's PySandbox is another interesting tool for safer server side execution, but doesn't protect against various things like memory exhaustion. You need OS level tools for that, hence the elaborate NCSS approach.
There's also a shell example already, with source:
http://shell.appspot.com/
http://learnpython.org/
It's pretty fun and everyone can contribute.
Add a comment: