One step beyond Java

A JVM language with a difference: Eclipse Xtend (now with Android)

Chris Mayer
xtend1

Eclipse’s statically-typed JVM language has just received a bumper update. We talk to co-creator Sven Efftinge about the newest features.

The number of JVM languages competing for the attention of Java developers is never-ending, all offering different modern language concepts that go beyond bog-standard Java. But what if you haven’t got the time to learn the new syntax and frameworks that come with Groovy, Clojure and Scala? A relatively new JVM language that compiles to Java in a method similar to CoffeeScript offers a new approach – to simply leverage the best within Java and cut down excessive boilerplate code. First appearing in an Eclipse release train last year, statically-typed Xtend claims to offer the modern features seen in other JVM languages, such as closures, but without throwing the baby out with the bath water

“The idea is to free developers from the limitations of Java without tearing them into a whole new world,” co-creator Sven Efftinge told JAXenter. “It translates directly to Java source and is also otherwise designed to fit into Java projects seamlessly.”

“In fact Xtend works better with many Java libraries than Java itself does, as it is designed for Java taking existing idioms into account,” he boasts.

Efftinge is keen to point out that Xtend offers “the expressive power” of other languages like Lisp, Smalltalk, Ruby and Scala, but “without compromising interoperability and tool support,” favouring to use existing Java tools and frameworks.

Xtend’s latest release, which is out today, enters new terrain with comprehensive support for Android – adding debugging compatible with the Dalvik VM and a Maven archetype. Efftinge believes that Xtend is as much for the developers coding for the mobile platform as those developing with Java.

“[They] face the same limitations in terms of expressiveness,” says Efftinge. “Android apps written in Xtend are as fast as if they were written in Java but the written code is much more readable.” The Xtend founder says that because the language doesn’t have a heavy library with it, the footprint of resulting Android apps is “pretty small”.

Xtend’s biggest change at the language level is the inclusion of macros, through a provisional API called ‘Active Annotations’. Developers can now declare annotations, to tell the compiler how to translate Xtend elements into Java.

Efftinge describes Active Annotations as “a secret weapon” for classical programming problems.

“You can for instance declare an annotation @Observable, annotate fields with it and get observed setter methods automatically generated,” he explains, before adding that changes happen on the fly.

Other new language features include collection literals, extension variables and extra support for declaring enums. You can check out the project homepage for more information, and all the latest changes can be found in the Eclipse release notes.
Author
Comments
comments powered by Disqus