Tag Archives: xtend

Eclipse and Xtend: some confusion in getting started

Last weekend there was some publicity around Xtend, an Eclipse project which extends Java with new language features. Xtend now has a new landing page, as announced by the lead architect Sven Efftinge.

I did intend to post about this yesterday, but I wanted to see it in action first, so I tried to download it and have a look. I believe this is a case where those who wrote the new landing page are too close to the project and made some assumptions, because I did not find it obvious how to proceed.

If you follow the Download link you are invited to paste one of the three URLs into the Eclipse update manager.

image

As a newcomer to the project, I did not want three URLs to choose from, I wanted just one. I picked Release as in general this one is likely to work.

Now, the instructions say:

To install the Xtend plugins open the update manager and paste one of the URLs on the right into the field ‘Work with’ and select the Xtend SDK.

The update manager actually presents you with a long list of updates, none of which say Xtend. I took a stab at what I thought was the right thing.

image

The All-In-One includes the Xtend SDK, which is what I want, right?

Wrong. After installation I could not find the tutorial which the docs said would be available.

I did some messing around with Eclipse and got the occasional error like this one:

image

Then I realised that I should have looked under the TMF Xtext-2.1.0 tree, which is where the correct Xtend SDK resides:

image

Except that if you find this helpful post by  Max Rohde you will know:

The other packages need to be selected since otherwise the Xtend editors will not work.

So you should select all of TMF Xtext-2.1.0 (or the latest release). Easy when you know, but not obvious since the word Xtend does not appear in the top node of the tree.

I was then able to create the tutorial project. I opened HelloWorld.xtend and got this:

image

Ah, but you have read Rohde’s post so you know this is expected and that you should run this as a JUnit Test. However it does not have any output. To see some output, you have to run one of the other examples, like Xtend08_RichStrings, or perhaps add:

sayHelloToSystemOut2(‘Tim’)

to the testHelloWorld() method in HelloWorld.xtend.

image

OK, it works.

So what is Xtend? It is essentially a code generator which lets you write in Xtend and generate Java. You can see the generated code in the tutorial project under xtend-gen.

image

Xtend adds some nice features: type inference, property syntax, closures, switch expressions with no fall-through, template expressions, extension methods, and multiple dispatch.

I can imagine C# creator Anders Hejlsberg smiling here, as most of this is already in C# in some form or other.

But is Xtend the right way to bring these features to Java? I am not convinced so far. It is an interesting Eclipse project, but it may be more significant in speeding the implementation of features like these into Java itself, than as a mainstream approach to writing applications. Xtend is a kind of hybrid approach, where you will be switching between Java and Xtend while you code and debug your application, and I suspect it would get frustrating.

There is also the question of widespread community support – beyond Eclipse.

Finally, it would be good if the new landing page could be made more helpful for those getting started.