Jython II

Acabo de recibir el libro de Jython que había pedido. De la introducción por Jim Hugunin:

The story of Jython begins in the spring of 1997, while I was working on my Ph.D. at MIT. While doing some benchmark work comparing the performance of Numeric Python to a variety of other programming languages, I was amazed to discover that Java was as fast a C code for simple numeric benchmarks. Previously, I had been uninterestred in Java because I saw it as an inferior replacement for Python. But I began to see the possibility that Java could be a replacement of the ugly and error-prone C code that I was writing for the performance-intensive parts of my systems.

After a week spent experimenting with Python on Java, I’d learned some exciting things. First, it was possible to translate Python programs into Java bytecodes by hand without any significant loss in performance. Second, the Java language had many similarities with Python and was a nice static counterpart to Python’s dynamic nature. Finally, I learned about the wonderful java.reflect package that made it possible to load and use arbitrary Java libraries from Python without having to write any glue code. This meant that it should be possible to download and interesting new Java library from the Net, put it on my classpath, and immediately start using it from Python.

That single week’s worth of experiments convinced me that there was a beautiful and elegant match to be made between Python and Java and I wanted to be the one to do it.

La primera impresión del libro es positiva. Cortito, poco más de 250 páginas ?lo que siempre es agradable, porque deja la impresión de que acabaré comprendiendo algo del asunto sin tener que leer 1000-, un repaso al índice da a entender que contiene todo lo que necesito saber para ponerme en marcha. En particular, el primer capítulo es francamente bueno. A modo de introducción, en lugar de explicar para qué puede servir usar Jython, los autores comienzan con un pequeño ejercicio interactivo en el que se construye una pequeña interfaz gráfica usando Swing desde Jython (primero hay que instalar Jython, claro, instalación que es asombrosamente simple. No me llevó ni diez minutos hacerlo, incluyendo el tiempo de bajarme el archivo correspondiente y leer los pasos a seguir en el apéndice A). Después de esa demostración, confieso que quedé muy impresionado. La sensación de poder añadir botones a un frame usando una sentencia simple como win.contentPane.add(eachButton) es casi mágica.

Según los propios autores:

Botanist know that if you cross-pollinate two different strains of plants, you create a hybrid; a new plant that exhibits the strengths of both its parents. Jython is a programming hybrid. It is an implementation of the Python scripting language written in 100% pure Java that runs under any compliant Java Virtual Machine (JVM). Using Jython, you can write Python programas that interact with any Java code. The Jython interpreter supports a number of shorcuts, which make using Java libraries as easy as using you own Python code.

Seguiremos explorando.


Deja una respuesta