This weblog is about my journey from TeX to Python and back again, taking in some interesting diversions. I’ve been using TeX to write mathematics and other documents for about 20 years, and admire its stability and high-quality output. I work for The Open University, the UK’s leading provider of distance learning, providing system support for the use of TeX to produce mathematics and upper-level physics courses.
For two days a week, until the end of 2009, I’m also working two days a week as part of COLMSCT, which is Centre of Excellence in the teaching and learning of Mathematics, Science, Computing and Technology. My project is Formulas in web pages and authoring formulas.
Come back in a day or two, and you’ll be able to read about my journey to Python and back.
Jonathan,
I’ve read your posts on the pyjamas project and the javascript newsgroup and (finally!) found your js4py project. I had actually started writing the same thing last weekend using Python 2.6′s “ast” module (as opposed to 2.5′s “_ast” module).
It is a relief and an encouragement to find someone else doing the same thing and to find all the code you’ve already written and released under an MIT license.
I’m with you in wanting a system that’s less ambitious than the pyjamas translator or the skulpt translator. One that converts syntax and provides some of Python’s syntactic sugar without needing to go all the way and smooth over all the differences between the two languages. I really liked your page where you outline a number of “gotcha” differences between the languages.
The #1 thing for me is generating clean code. This is critical both for debuggability and also for publishing the generated Javascript publicly (I would like to create cross-language modules that can be consumed both by Python users and Javascript users).
In using py4js, I found a number of things I would like to work on. One of them I would like to consider is porting it to the Python 2.6 “ast” module, as it is higher-level than the “_ast” module.
Another is allowing import of pure javascript namespaces that aren’t written in Python and aren’t being converted with py4js. For instance, webtoolkit’s base64 javascript module could be imported with python like “from webtoolkit import base64″, which might be translated to javascript like “import(‘base64′).from(‘webtoolkit’)”.
There are a number of smaller changes, things like putting variable declaration and assignment on the same line (“var n = …”), avoiding repeated, unnecessary variable declarations (if a variable is assigned in an “if” scope, a second, unnecessary “var” statement is generated), changing “new Kwarg” to something more compact, perhaps simply “kw”, removing some unnecessary grouping parenthesis and String() typing around string concatenation, and possibly looking at a non-generator approach to “for” loops.
I would also want to do lots of documentation/examples/doctests (using Sphinx) to really widen the web presence. I think a project like this could get a lot of steam if people saw the quality of the javascript being generated and that it really is a viable alternative to writing client-side code in JS (I would want it to operate cleanly with Prototype, jQuery and other JS frameworks).
I would also like to write a little helper utility that uses a FileSystemWatcher to auto-convert any .py file in a set of folders to a sibling .js file any time it is saved, to make the development save/refresh cycle faster.
Also, I’d like to contact mccarroll (www.mccarroll.net), who has done some similar work with his “py2js” and Aza Raskin (www.azarask.in) with his Pyscript.
Does any of the above sound like a direction you’d like to go with py4js? In other words, should I approach you with patches or fork the project and host it elsewhere? Are you interested in converting to mercurial or would you rather stick with svn?
Let me know your thoughts,
– Peter Rust
Developer, Cornerstone Systems
Thank you for your interest, Peter. I’m glad you’ve found js4py and like it. Yes, do contact Naill McCarroll and Aza Raskin about this.
I’ve started using BitBucket http://bitbucket.org/jfine/. You might be interested in testutil, whose goal is to write cross platform tests in Python. So you write tests in Python and compile them to JavaScript!
Finally, you might be interested in jsmod, started on Google http://code.google.com/p/jsmod/ and in the process of moving to BitBucket http://bitbucket.org/jfine/jsmod/overview/.
Hi Jonathan,
I recently decided that JavaScript’s lack of a good, unified, open, organized (ahem… JSAN) and centralized module infrastructure was a bit too annoying, so I set out to make one of my own. Upon trying to come up with a name for the thing, I stumbled across your jsmod concept.
It doesn’t look like you’ve done anything with it, so would it be agreeable to you if I were to take over the project name/space, or at least get write access to the repo on Google Code?
Let me know what you think,
– Philip Peterson
Hello Philip
Thank you for your interest. I’ve moved/restarted this project on bitbucket: http://bitbucket.org/jfine/jsmod/. Why don’t you, for now, clone that repository and start coding if you wish.
Jonathan