Introduction
Xtend is a programming language developped at the Eclipse Foundantion which is compiled/transpiled to Java source code. It is a general purpose programming language, but is used a lot in Model Driven Software Engineering (for Model to Model as well as Model to Text transformaions).
This talk is not an introduction to Xtend, but the features shown are close to Java syntax. Therefore at least a firm familiarity with Java is expected for attendees of this presentation.
The presentation will highlight some Xtend language features and shows how these features enables you to craft more ergonomic and more concise code and APIs. Some of the shown use cases are not very obvious when working with Xtend at first. All examples will be showcased by examples using the open source Xtensions library (maintained by the speaker), which provides a fair amount of Xtend utility classes and methods for Xtend users.
Planned Content
It is planned to show case at least the following topics and Xtend language features together with the benefits they bring for Xtend programmers:
Extension methods
Extension methods allow to define methods that can be used as if they are instance methods for a certain type even though they are defined outside of the type.
This enables the user to provide additional functionality without maintaining a fork of the code to be augmented via extension methods. This allows for example providing a forward compatibility layer for newer versions of an API (e.g. JDK classes), which allows smooth transitions between versions of a dependency. This point will be demonstrated by showing how the Xtensions implements some Java 9 APIs as extension methods on the Optional type and how code using these methods can be used on Java 8 and on newer versions of Java.
Powerful type inference
Compared to Java, Xtend has more powerful type inference (especially for lambda/closoure types), without having to give the compiler additional context.
This feature can be leveraged to provide more concise and readable APIs, which will be shown by examples how the Xtensions library improves the usability of the CompletableFuture JDK class via extension methods.
Every exception is a runtime exception
In Xtend every exception is thrown as a RuntimeException. This feature may seem controversial at first, since the compiler does not enforce error handling. However lambda heavy APIs like the JDK Stream API do not work well with checked exceptions. The presentation will show what types of error handling
can be enabled when all exceptions are simply unchecked. It will also be shown how the user of an API can be forced to handle errors anyways in case it is deemed necessary by the author of an API.
Bonus hack: Extension objects + anonymous types + type inference
A limitation of Java when using lambdas defined in methods is that the lambda body cannot write to variables in the scope of the method. A combination of extension objects, anonymous types and type inference can be used to emulate this feature with minimal boilerplate code. This feature is especially useful when testing lambda-heavy APIs.
Q&A
The Q&A session can also be used for questions regarding all things Xtend, such as IDE support, usage for Xtend for MDSE, and other topics of interest regarding Xtend.