JRuby and Jython: the easy way

February 9, 2009
By
This entry is part 4 of 17 in the series Programming Languages

The revamp of Jython 2.5, the python interpreter written in Java, is a very good news, because give us the chance to think of a new way of coding. Looking at Google trends,  JRuby and Jython are emerging as key  pieces of a new puzzle.

OOP revolution take years to become active, and Java success is based on about 15 years of trials, errors and refinements.

After some considerations, at Gioorgi.com we are evaluting a new approach to java  programming.
New methodology emerge slowly, and it is not easy to find what is userful to day-by-day programming. One of the true success of OOP is the reduced mantenance costs, because OOP has a stronger isolation of related concepts.

So let’s start from academic research, to see what can help us to reduce maintenance costs.

If you take a look to  Traits: Composable Units of Behaviour, published on 2003 by Nathanael Scharli, Stephane Ducasse, Oscar Nierstrasz, and Andrew P. Black, you read:

[…]A trait is essentially a group of pure methods that serves as a building block for classes and is a primitive unit of code reuse. In this model, classes are composed from a set of traits by specifying glue code that connects the traits together and accesses the necessary state. We demonstrate how traits overcome the problems arising from the different variants of inheritance[…]

Traits differ from classes in that they do not define any kind of state,
and that they can be composed using mechanisms other than inheritance.

Building dynamic traits is an interesting approach to programming, similar to Aspect Oriented Programming (AOP).

Anyway both ideas (traits and AOP) have been proved a bit unsuccessful in the day-by-day programming. After looking at the implementations,   a small peak on google shows only experimental projects.

A web framework based on dynamically service composition, can be an interesting step for shortening Java coding time.

In this context, the Java-Python bridge (Jython) a dynamic interpreter, is a better solution then a compiler, because give us more freedom. Also JRuby shares a similar approach.

Let’s see the key point of this idea:

  • There is no need of learning a new library, but it is possible reusing as much as possible JDK know-how.
  • Python offers lambda functions, a powerful way of defining scoped and parametric functions. This is impossible in Java, and similar approach (based on CGLIB or Spring for instance) are  slow to set up, understand and debug. Teams need to be trained a lot, and this can increase development costs.
  • The ability to extend Java classes via  python code gives you a strong flexibility
  • The dynamic aspect of python simplify coding of prototype parts and mock objects
  • Python has several advantages on its own:
    • Python is older then similar dynamic scripting languages.
      Python was created in the early 1990s by Guido van Rossum at Stichting Mathematisch Centrum.  Also Ruby has a similar born date, but it has grown slowly.
    • Python code is easy to understand compared to more mature scripting languages (like perl)
    • Python library is rich
    • Python community process (PEPS) is well established, and live
  • The security model of Java protect us from abuse. This has been a problem in python. For instance a web framework written in pyton (called Zope) suffers from this lack of security and isolation. This issue is common also to Ruby as a dynamic language.
  • Java memory management  is stronger then the Python one.
  • Java multi-processing abilities can leverage python lacks on this area
  • Java is slowly moving toward scripting languages. JSR 223 is an example. At the moment, there are the following scripting engines:

For these reason, Jython/JRuby look promising for prototyping and developing.

References

Series NavigationPython functional programmingClosure in Java: fast and nice!

Tags: , , ,

Leave a Reply