jpython.nw

The jpython Language

As an example of an interactive language with relations to Java, jpython provides some interesting points to ponder. And, it's not a bad environment for experimenting and (with some limitations) for developing Java software. The language is, essentially, identical to the python language. This is an interactive language, presented in its tutorial as a programming language to replace large shell scripts or to develop software quickly as an alternative to C. The grammar of python is C-like, but not an extension of C (the same statement is true substituting ``java'', ``S'', or other languages in the same grammatical style). The language is extended by writing collections of software (modules) in python itself or in C. The jpython language is a pure Java implementation of essentially the same grammar. In particular, it can load existing python source files. In addition, it can import Java packages and class files, within some limitations. In effect, it uses the same import command to import either python modules or Java packages, with the interpreter handling the two cases suitably. The source of jpython is available for downloading, the documentation is primarily that of python plus some web pages of specific material, and there is a mailing list for discussions.

The Scripting Languages View

[*] It's interesting to read the view of Guido van Rossum, the father of python, in an article on Java and Python, and a related article by Ousterhout on scripting languages. They both argue that ``system programming languages'', meaning C++ and Java, should be supplemented by ``scripting languages'', which one might guess means python and Tcl, respectively. Actually, van Rossum is particularly enthusiastic about the jpython version (which I take to be essentially the work of Jim Hugunin), because of its ability to run Java code. The argument, which Ousterhout expands on in more detail, is that scripting languages give a big boost in programmer productivity (for certain tasks anyway), but that object-oriented system programming languages do not. Personal comment: This argument has much in common with a view held, I think, by many of us in statistical computing, that an interactive language for computing with data is an essential supplement to traditional programming, because it lets users develop their ideas faster. Where there seems more room for debate is in the sharpness of the contrast between scripting language and system programming language. For perhaps obvious reasons, both the authors assume that the scripting language will be defined independently of the system language, as is the case with both python and Tcl. But is that really the way of the future? In particular, van Rossum ends up in a slightly contradictory position when he enthuses over running Java class methods from jpython (and it really is a nice feature) while being rather negative about Java as a programming language. Isn't it possible that we can design the next generation of ``scripting'' languages to be natural extensions of a language such as Java? The end result may not differ all that much, but I will argue for the moment that unless one is already committed to python, for example, there is the chance to have a more seamless transition between the scripting and system program worlds, and maybe the happy programmer eventually won't need to worry about the difference.

Choices about Compatibility

[*] The jpython approach illustrates some interesting choices in developing an environment around Java and the Java Virtual Machine. If one starts from an existing language and related software, as the python folks did, there are three attitudes to compatiblity:
  1. be compatible with your earlier language;
  2. be compatible with Java;
  3. don't bother about it.
The design of jpython took the first choice (there are some incompatibilities, but most of them are fairly detailed, or else inevitable, such as not having access to C-related extensions in jpython). The big plus for this choice is that much of the existing python software becomes directly available in jpython. What about Java compatibility? The approach in jpython is to build on the notion that python ``looks like'' Java in a number of key respects, such as importing, method invocation, and (somewhat less so) class definition. Python classes can extend Java classes; there is an ability, within limits, to compile the jpython class into a Java class. How well does this work, if our motivation is mainly to develop some new capabilities, not tied uniquely to python? Based on some preliminary experiments, it provides quite a usable environment, but the main limitations are likely to come from fundamental differences in the semantics, particularly in data types. For example, python does not have a direct analog of the array notion in Java (or the sequence construction in CORBA IDL). There is a workaround in the form of what's called jarray, which is helpful for interfacing to Java classes but really uses a list-like structure, not a Java-style array mechanism. There are other, more detailed limitations; for example, there is only a partial ability to reload Java classes during the jpython session, meaning that detailed debugging can become tedious. Some come from the syntax (and especially, from a number of reserved words) in the python language, and so are inherent. Fortunately most of these are not very bothersome. Others problems, such as the reloading, are not inherent in the jpython definition, but would require some fundamental changes in the implementation.

What Do We Want?

[*] We all have a variety of interests, and jpython naturally isn't exactly related to any of them. It seems that the second compatibility choice is more attractive for us than it would have been in the python case. My own preference would be for a Java-compatible interpreted language that would then be extended in various limited ways to provide the kind of interactive, quick-programming ability we expect and that Java itself lacks. Even some limited experimenting with jpython made it clear that one would end up designing Java classes with one eye on what couldn't easily be done in python. If the main interest was in data-lean applications (e.g., designing GUI interfaces) the loss might not be too serious. But it seems likely that many of our applications will either involve some significant design of data types or will lean heavily on the areas where python and Java differ (such as basic array types). Nevertheless, experimenting with jpython and looking at their implementation approach is a useful way to play with something that actually exists.