Tuesday, March 31, 2009

Another reason to fool around with MeTA Studio: Python support

Well yes! Many had asked for it so now here is it!

First a bit of history. When I started developing MeTA Studio, I did evaluate Jython (Python implementation for JVM) along with BeanShell and many others. But then finally decided that BeanShell would be the first class scripting interface for MeTA Studio with provision for adding any other scripting language that is targeted for JVM. There were couple for reasons for this decision:

- Jython is too heavy. At about 3 mb (with no debug info). My modified BeanShell is 800kb while if u compile it with no debug info it boils down to a mere 200kb!!
- Prototype-to-production. Python code, though easy to write, doesn't translate easily to Java code. It is very easy to prototype in BeanShell and put it into Java.
- Speed. While BeanShell can run at native speed of Java (i.e. after you compile the code for a target JVM), Jython is purely interpreted, and it was definitely orders of magnitude slower than BeanShell. When I tried Jython the first time many years ago it was about 40-50 times slower than BeanShell, enough to keep me away form making it the primary scripting interface for MeTA Studio. In recent times though Jython has improved substantially. In many cases faster, but not as flexible as BeanShell in terms of the earlier point(s).
- License. It is not LGPL/BSD... So I will only distribute it as a separate addon package (maintainers are needed here ;) !)

and why it is included now:
- IBM supports Jython in their enterprise apps like websphere, I want to impress them ;) With rumours of them taking over Sun.. (Glee .. Well now wondering on that as Oracle plans to buy them instead!)
- I want more developers and users for my platform!!
- Proof that other languages can be easily supported, with out changing anything within the core IDE!
- I want to have fun ;)

Well the complete Jython support for MeTA Studio was added with about 4 days of work, which largely involved writing appropriate wrapper functions akin to BeanShell. And thanks to ways to add external library and widgets framework in MeTA Studio, there were no changes made to the core IDE specifically incorporate Jython support.

So you wanna give a try? Here is how:
The installation instructions are same as previous, but again ..
0) Ensure u have v 2.0.01042009 or a higher version installed. Project URL: [http://code.google.com/p/metastudio/]
1) Unzip metajython.zip (download from: Jython support file on Skydrive) in meta/lib/ext
2) Shut down MeTA Studio if it is already running
3) from command line:
meta/bin >$ java -jar MeTA.jar --addlibs jython
(you can skip this step, if you have already done so with the previous builds)
4) Start MeTA Studio, open the code editor. Then open jythonWidget.bsh from meta/lib/ext/meta-jython directory
5) Click on Make Widget to get the Jython widget on the the widget panel

Now you can either use the shell (like the usual python shell) or use the editor to write code in python as you would normally do for BeanShell scripts.

I will be putting up user guides on how to use the Jython support in MeTA Studio at: http://code.google.com/p/metastudio/wiki/PythonSupportForMeTAStudio. You are also strongly encouraged to contribute to the wiki, just drop me in a mail if you want to!

Now that Jython support is out, would like to state few things about future of this Jython support of MeTA Studio:
- Firstly, BeanShell will always be the primary scripting interface in MeTA Studio. Meaning that all new releases of MeTA Studio will come installed by default with BeanShell as has always been the case.
- Jython will never be distributed along with binary distribution of MeTA Studio. This support will always be available as an external download as is provided above.
- Since this project is getting big day-by-day, it would be really nice if some one can take up the responsibility of maintaining the Jython support in near future. Though I would maintain it with a bit less priority till I can get a maintainer for this port.

Fool around ;-)

No comments: