Angular shitstorm: What's your opinion on the controversial plans for Angular 2.0?
Xpand your horizons

Xtend – a quick look at the pros and cons of an up-and-coming JVM alternative

Coman Hamilton
Edit-Xtend

It’s got lambdas, it’s flawlessly interoperable with Java and it’s also a cinch to learn for Java devs. So what’s the catch?

“Look at me! Look at me!” The volume of JVM languages screaming for attention from Java developers is steadily rising. Somewhere in the deafening crowd of Java alternatives is a small language called Xtend. “Over here,” it shouts. “I have lambdas! I’m really smooth and I’m totally easy to learn.”

But can you trust it?

Put simply, Xtend is to Java like JavaScript is to CoffeeScript: a more concise language that compiles to Java in order to help devs cut down on their boilerplate code.

Having started out in Xtext, Eclipse’s framework for developing programming languages, Xtend appeared in the Eclipse release train in 2011, and has since proven itself a handy language for Android developers. One commentator even goes so far as to call it Android’s answer to Swift.

As you can see in the Hello World example, Xtend runs pretty much like Java – except for the use of def to declare a method.

class HelloWorld {

def static void main(String[] args) {

  println("Hello World")

}

}

With a “look and feel” that could be compared to Groovy, this statically-typed language adds quite a few gems to the feature list of other JVM languages: a null-safe feature call, more prevalent final variables, being able to clean up RxJava boilerplate, aaaand…

Flawless interoperability, yay!

Xtend has at least one major bragging point where JVM alternatives like Scala, Clojure and Groovy are lacking: error-free interoperability with Java. Xtend can do this because it looks and works exactly like Java’s type system, so there’s no chance of any impedance mismatches between Java and Xtend code.

Essentially, this means you can invoke code from Java and vice versa, but best of all, this makes learning Xtend easy for anyone that’s already familiar with Java’s type system. Co-creator Sven Efftinge told JAXenter the idea behind Xtend is to “free developers from the limitations of Java without tearing them into a whole new world.” That’s a major plus for would-be alternative programmers that don’t have time to get their head around the foreign syntaxes of Groovy and Scala.

Can I get that with lambdas?

Xtend also gives you the chance to use your favourite new Java function: lambdas – perhaps nothing to write home about for those of us already on Java 8. But then again, Xtend’s lambdas compile to anonymous inner classes, which is perfect for Android developers that need that function for click listeners.

Size and readability also rank pretty high for Xtend, especially for mobile devs as Efftinge explains: “Android apps written in Xtend are as fast as if they were written in Java but the written code is much more readable.”

No IntellijIDEA support, boo!

As developer Andre Medeiros explains in a lengthy blog post, Xtend is still far from perfect. One of the biggest drawbacks is the lack of support for IntellijIDEA. So far, Xtend has most been an endeavour of the Eclipse Foundation, although an appeal has been started for an IntelliJIDEA plug-in. Another problem, Medeiros notes, is the additional compilation step when building an apk, which means an Android application needs around 20 entire seconds to compile an entire project –  life’s short enough as it is, right?

If you’d like to Xtend your knowledge (sorry, couldn’t resist) about the nifty features of this JVM alternative, check out the extensive documentation or this video about using Xtend for code generators.

Author
Coman Hamilton
Before joining S&S Media Group as Editor of JAXenter.com, Coman completed an M.A. in Cultural Studies and wrote for numerous websites and magazines, as well as several ad agencies. Coman also manages the tech publisher developer.press. // Spotted a typo? Want to submit a story? Email coman[AT]jaxenter.com
Comments
comments powered by Disqus