Taking Java further

Eclipse Xtend: Java’s equivalent to CoffeeScript


We speak to Sven Efftinge and Sebastian Zarnekow about their new JVM-based programming language that compiles into readable Java code.

From the June edition of JAX Magazine, Sven Efftinge and Sebastian Zarnekow introduce us to their new JVM-based programming language that compiles into readable Java code, Xtend.

JAX: Can you give us a brief description of Xtend?

Sebastian Zarnekow: Xtend is a statically typed programming language running on the Java Virtual Machine. It’s designed to jazz up Java a little, to address the weaknesses that Java has accumulated over the years. Our goal is not to abandon Java altogether, but rather to complement it, so that it can be integrated into in any given project. The idea is to make it possible to draw on Xtend in any Java project situation, so that one can find smoother solutions to one’s problems.

JAX: You were just talking about Java’s weaknesses. Can you elaborate on what weaknesses Xtend addresses?

Sven Efftinge: Principally, Java is a relatively well-designed language. The upside is that there are little surprises compared to other languages. The downside is that it’s quite old and what they call ‘ceremonious’, meaning you have to communicate with the compiler a lot, you need to write down a lot of types twice, and use brackets and semicolons everywhere; you don’t have closures or lambda expressions; if you want to use JavaBeans you have to call Getters and Setters; there is no operator overloading. All those problems were solved in Xtend, in a way that is very easy to understand. And since Xtends immediately compiles to Java code, you can always see what you are doing. It’s perfectly readable, it’s like CoffeeScript for JavaScript.

JAX: There are other languages that pursue similar goals, though. What sets Xtend apart from, say, Groovy?

Efftinge: Groovy has a similar thrust, but is a few years older. We adopted many good ideas from Groovy, but also from Scala and from Java. Unlike Groovy, Xtend is statically typed, with the same type system as Java, including generics, which are exactly the same, just as the conversion rules. What this means is that the ten million developers out there who know Java will understand it immediately. In addition, there is much better tooling: you get content assist and compiler checks in Eclipse, all the things you’re used to from Java. The code that is generated is very fast compared to Groovy. A well-known problem with Groovy is that it’s fairly slow.

Compared to Scala – it’s simpler! That’s the most important difference. You can use different IDEs for the language because the type system is not as extreme.

JAX: The two of you are also the key men behind Xtext. What’s the connection between Xtend and Xtext?

Zarnekow: That’s quite an interesting question. Basically, what we did with Xtend was to create a full-blown programming language based on Xtext, in the course of which we developed a reusable expression language for Xtext that is now embeddable into any domain-specific language. It’s now possible to build nice APIs with Xtend and one can generate very readable code by means of concepts such as extension functions, operator overloading etc. In certain situations one might still get to the point where the abstractions are not sufficient, but since Xtend is based on Xtext, it allows for exceptionally good integration with external DSLs, so that one can operate seamlessly between Xtend and Java or Xtend and a DSL within one and the same project. This is another one of Xtend’s unique features.

JAX: Any specific projects you have tackled so far, using Xtend? If so, which ones?

Efftinge: Xtend is still very, very young. We released a preview version as part of Eclipse’s release train last summer (Indigo, editor’s note), followed by a minor release last winter. A really interesting release is coming up in June, as part of the next release train (Juno, editor’s note). It will be very well integrated, and the language will be quite complete already.

We make extensive use of Xtend in our own projects. Many people start using it for JUnit testing, because there it’s interesting to have a good syntax and compact test cases so that you are actually able to see the test data. With Xtend, you can generate great builder syntax and multi-line strings. So that’s where it’s used a lot. The Google Group have used Xtend for Android development and GWT. The great advantage is that it translates to Java code rather than bytecode, so you can use any platform that works with Java source code, such as GWT, which translates to JavaScript. This is not quite as easy with Scala.

So, in general, no big projects so far, but a lot of people have just started experimenting with it, they find it exciting – and I’m curious to see first results. We’re mainly involved in open-source development. We support customers developing languages with Xtext, and when it comes to building things like code generators, Xtend comes in handy. But so far, we haven’t written any big business applications using Xtend.

JAX: The final question’s for you, Sven: You won one of this year’s Eclipse Community Awards. You were honored as Top Committer. What does this award mean to you?

Efftinge: It made me very happy, obviously – especially because the award winners are selected by the community. It’s not like the decision is made by a jury of five people, but the entire community is allowed to vote. It’s a great award. Sebastian won it last year, by the way, so let’s wait and see who’s next.

This interview was originally conducted in German by Hartmut Schlosser and Diana Kupfer at JAX in Mainz, on April 19, 2012. It has also been published in our sister publication, JAX Magazine.



All Posts by HartmutSchlosserandDianaKupfer

Inline Feedbacks
View all comments