Monday, February 28, 2011

Xtend2 - What's In The Pipeline?

In the last weeks, the Xtext team has been busy with creating Xtend2. Xtend2 is the successor for Xtend and Xpand and implemented on top of Xbase1. I think we made really great progress both within Xbase - which is a reusable expression language that can be embedded into any language that is developed with Xtext - and with Xtend2 itself. 


Xtend2 provides some unique language features and great Eclipse based tooling. It's really a pleasure to see how the well choosen orthogonal concepts interact with each other and how their total creates a language that feels as fantastic as Sven predicted.
  • The extension concept of Xtend2 allows to import extension methods in a static and in a dynamic manner. Dynamically imported extensions are injected into your instances by means of dependency injection. It is really straight forward to create a customizable and adoptable code generator simply be using well defined components that are assembled by a DI container such as Google Guice.
  • Polymorphic dispatching allows to invoke overloaded methods according to the runtime type of their arguments instead of a static decision. This is especially useful if you want to process heterogenous data structures such as EMF models. It is even possible to rely on this runtime binding when you use Xtend2 classes from Java code.
  • Even though Xtend2 compiles to java code which is not dependent on JDK7 (or later), we provide full support for closures. Writing own higher order functions that take closures as arguments or return function types is possible, too.
  • Type inference works for expression trees and across method boundaries. It is usually not necessary to define the type of closure parameters, local variables or the return type of methods since the type system will derive it automagically. It works great with generics, too.
  • Xtend2's rich strings allow to write code generator easily. We came up with a neat solution for the classical whitespace problem in template languages. The IDE support that includes validation of template indentation, quick fixes and semantic highlighting helps to write code generators or compilers in a readable way while the output looks nice, too.
  • While we're at IDE support, did I mention the refactoring capabilities, content assist, hover information or the other features that are available in the Xtend2 editor because?


If you are at EclipseCon and as eager to get your hands dirty with Xtend2 as I am, make sure to attend the tutorial that Jan, Sven and I will give there.

[1] The Xbase development is sponsored by itemis and the Federal Ministry of Education and Research.
 

2 comments:

Krzysiek said...

So as I mention in a tweet, I consider some things ambivalent (and need to see how they work out):
- it's a (another) General Purpose Language. It may be hard to sell GPL as there are plenty of them. It is great at creating string/file output, but it seems more complex than other dsl-s that can do that (usually one consider gpl-s more complex ;)). Do you plan to use it as www view technology too?
- it looks that migration from old xtend would lead to more code
- Java Generics
- non default polimorphic dispatch. Feels like C# non virtual methods ;) I would like a compilation unit flag (or less likely workflow param): "dispatch all". It would potentially ease migration and spare some chars.
- classes, probably are good to modularize code, but I would like them to be optional (e.g. like in Groovy). Maybe they are optional already? It would potentially ease migration a bit.

Things I don't know yet:
- implicit create - in xtend I could create any type of object based on any params e.g. String(role of object) that was not set to any field in the object but send as additional parameter. I am not sure is it still possible e.g.:
create new Class("Role1") { name = foo.bar }
- id there also xpand-like form of template definition?
- will you provide automatic transformation from xtend to xtend2?
- is DI meant to totally replace old AOP?
- how one configure DI (e.g. how to write old around method in xtend2)?
- how hard would it be for 3rd party to add new elements to xtend2 (e.g. a www template language with new "cached" keyword that would cache function output like create but use persistent ehcache for that)

I like:
- whitespace handling! (maybe not the most important feature(as long as you don't code in python), but great idea)
- true closures
- Generics

Regards,
Krzysztof Kowalczyk

Unknown said...

Krzysztof,

>> Do you plan to use it as www view technology too?

I'm not sure what you mean by www technology in the context of Xtend but no, there are no plans in that direction from our side.

>> it looks that migration from old xtend would lead to more code

What do you have in mind? The surrounding class?

>> Java Generics

Yes, that's an advantage since developers are familiar with the semantics.

>> non default polymorphic dispatch

We consider polymorphic dispatching the exception and not the common case.

>> Classes

This is actually an advantage since you do not end up with synthetic class names and you can use Xtend code transparently from Java code.

>> Create extensions
We will have something like this. Not yet but soon. So far you can build something similar with higher order functions.

>> Xpand like templates
No.

>> Automatic transformation
There are no concrete plans.

>> DI instead of AOP
Yes, that's the point.

>> Around method in Xtend2

You extend the generator class and override the method that you like and do you stuff before and after calling super.

>> Add new language features to Xtend

Xtend is not designed to be extended on a language level. But you are always free to use the standard Xtext extension mechanisms. However, 'cached' is a good candidate for a library with higher order functions.