Dienstag, 14. Oktober 2014

Xtend - The Series


Xtend is a statically typed programming language that compiles to readable Java code. It stays true to Java's type system and libraries, giving it the best interoperability of all the popular JVM languages. On top of that it adds a lot of syntactic sugar and powerful abstraction features that really cut down on the boilerplate you have to write. Together with its flat learning curve, top-notch IDE and build-system integration, it is easy to pick up and will give you immediate benefits.

The release of Xtend 2.7 has brought about a new milestone of language features, performance and IDE integration. So much has been done over the last few releases that I thought an up-to-date blog series was in order. I still see a lot of outdated information and misconceptions floating around the world wide webs. So even if you already gave Xtend a try one or two years ago, there is a lot to be learned.

In the first post of this series I will show you how to get started and how to reach the community. In the following posts, I will present individual features of Xtend in-depth. So stay tuned =)

Easy setup


To use Xtend inside Eclipse, just follow the links on the download page. You can look at some examples by using New->Example->Xtend Introductory Examples.

Xtend classes live right next to your plain old Java classes. Xtend needs a small runtime library. If your project doesn't have it yet, you will get a quickfix the first time you try to edit an Xtend file.

If you are like me and prefer to set up your projects using your favorite build system, we also got you covered. For Maven, there is the Xtend Archetype. Eclipse's Maven integration will take care of the rest. For Gradle, you can use the Xtend Gradle Plugin. Using that, just call gradle eclipse on the command line and you have a fully configured Eclipse project.

Flat learning curve


Xtend's basic syntax is almost identical to Java, so programmers coming from there will feel right at home. They are actually so similar that we will provide a Java->Xtend converter in the next release.

One important difference is that in Xtend, everything is an expression and has a return type. So you can for instance assign the result of an if-expression to a field. No need for (static) initializers or similar ugly constructs.

Also, Xtend enforces the distinction between defining a method and overrides, reducing potential errors. Apart from that you will notice that Xtend has better visibility defaults: Classes and methods are public, fields are private.

Xtend's switch expression can switch over anything, making it a good alternative to if-else cascades. And if you do type checks in switch- or if-expressions, then Xtend will automatically cast the variable for you inside the corresponding block. So even before learning anything about the advanced language features, you are already getting some benefit over Java.



Community


Xtend has a very friendly and helpful community. You will find enterprise developers, Eclipse plugin authors and Android App writers all taking part in discussions. The Xtend team takes inquiries very seriously, looking through the forum and answering questions on a daily basis. Just drop by if you have any questions or want to share some cool library or success story. We are looking forward to having you on board!