[Edu-sig] On Jython for education

Paul D. Fernhout pdfernhout at kurtz-fernhout.com
Wed Oct 19 15:26:02 CEST 2005

Brad Miller wrote:
> If it does turn out that Jython becomes a thriving, active version of  
> Python then I think it would be very interesting to investigate.   
> Have you used Jython?  What has been your experience?  Maybe others  
> are more in the know about the future prospects of Jython?

We're using Jython for a medium sized commercial project (using the latest 
stuff from CVS) and it seems to be working quite well. However, whether it 
is easy enough for learning is a different matter.

The value of Jython (to us) is in the ability to use Python syntax and 
features and yet access a huge array of Java class libraries and then be 
able to say to a client we are "using Java" without suffering through 
endless braces and casts and type declarations and so on. (And 
realistically, Java does provide a lot of enterprise level libraries, or 
at least says it does.)

Personally, I prefer the Swing API to wxWindows (what I use under 
CPython), however the cost of that is not being truly open source (Google 
on "The Java Trap") if you use Sun's class libraries and JRE stuff and 
also having a huge footprint in memory use (30MB+) whereas python + 
wxWindows is much smaller (both memory and installation needs).

Of course that is slowly being balanced by the fact that if someone 
already has a JRE (Java runtime environment) installed, which is more and 
more common, all you need to give them is a 1.5MB or so Jython jar file. 
Supposedly JRE 1.5 does a better job of sharing memory for common code 
across all JRE users. And GNU classpath (free as in freedom Java 
libraries)  is moving along.

As for Jython's support, it does have some active users, but obviously it 
does not have the volume of posts to the mailing lists that Python has. 
Also unlike the Python mailing list there have been quite a few unanswered 
questions especially in the past (i.e. I sometimes Google on some Jython 
issue and find someone else asked it but there was not a reply, whereas 
Python rarely has that). However, many questions related to Jython in 
terms of how to use widgets can instead be answered by looking at Java 
forums for ideas. There really isn't that much Jython specific stuff (as 
opposed to Java specific stuff) to know unless you are hacking the Jython 
codebase, and that one of the beauties of Jython (for people comfortable 
with Java). And despite the limited volume of the mailing list, except for 
missing features of later Pythons, Jython 2.1 from a couple years back 
seems to have a good reputation for stability. Due to the Python Software 
Foundation's wisdom in funding work on Jython it is moving along towards 
later Python compatibility and at least for a short time better supported. 
I think that was an excellent choice by the PSF (and I say that seriously 
as someone who had a rejected proposal [Delphi -> Python conversion]; 
investing in Jython was a better choice, and even I am now benefiting from 
it). I think Jython will remain an excellent place to invest 
Python-related money and effort -- it really does open Python up to a 
broad spectrum of situations.

I think Jython could be made into an excellent educational environment 
(including being usable in later web browsers linked to a late model JRE, 
which would be a big deal for use in schools!) but it would take some 
work. The biggest issue is that to use most common Swing classes in Jython 
like JLabel and JTree and JList, you need to read and mentally translate 
to Python syntax the Java documentation (sort of like how in wxWindows you 
need to read the C documentation, but wxPython at least has a nice demo of 
all widgets and Jython Swing does not). This is quite a bit of a hurdle, 
though not that bad for an experienced or motivated programmer, especially 
if you already know Java. That issue might be solved by just making better 
documentation of Swing for Jython (though who would want to maintain is, 
if it wasn't generated automatically?). [There are also some Jython idioms 
which make the code smaller than straight Java to Jython translation by 
dropping all the typecasts and type declarations which are not obvious at 
the start.] Or alternatively, one could just make special educational 
classes for novices which would be like training wheels (think 2D turtle, 
etc.) until kids could start using Swing. There are two Jython related 
IDEs now for eclipse, so perhaps one of them could be modified for 
education use as well (though Eclipse has its own learning curve).

And for learning, as in another post in this thread, some issues like the 
ease of making typos might need to be addressed somehow. Smalltalk, 
another flexible system designed for kids, requires local variable 
declarations as names to prevent typos (which I like, personally, as 
opposed to mandatory type declarations) and warns you when you save code 
that uses an undefined function (actually,undefined  "selector" of a 
method, in Smalltalk jargon). Given the source is there, it might be 
possible to add this requirement somehow to Jython, but that would break 
some Python compatibility? I would not mind this typo problem so much if 
Jython, like most Smalltalk, allowed you to easily modify running code in 
the debugger. So, that would be another approach to making the type 
problem less of a bother -- adding better support for modifying code while 
running (and I have made some experiments in that direction). However, for 
small learning programs, rerunning the code from scratch (especially under 
JRE 1.5 with quicker subsequent startup) might not be such a big deal.

As an aside, I was posting against Java (in favor of Smalltalk) in the 
newsgroups when Java came out, as I thought it was marketing hype and 
unneeded. And it was. But now, eight years or so later, Sun and cohorts 
finally have a lot of the bugs out (and have added so many features from 
Smalltalk like Swing and hot spot technology), so, given you can use all 
that stuff from Python with Jython, it isn't that bad a platform anymore 
(ignoring "The JavaTrap" license issue).

--Paul Fernhout

More information about the Edu-sig mailing list