Thursday, April 05, 2012

Xtend Examples used at EclipseCon 2012

As there were almost no slides in my EclipseCon session on Xtend, I decided to record the examples I used during the presentation. You can find the source code at github.

Here are the few slides I had:

Example 1 : Hello World

How to start given an empty workspace.

Example 2 : Hello SWT

SWT is well known at EclipseCon, so I decided to have another Hello World using SWT just to show how nice interacting with existing Java APIs (even older ones) can be with Xtend.
It mainly shows how to use lambda expressions where you would write clumsy anonymous classes in Java.

Example 3 : 99 Bottles Of Beer

An implementation of the 99 bottles song using Xtend. It shows the use of template expressions and extension methods.

Example 4 : Distances

The example I blogged about yesterday. Mainly covering operator overloading and extension methods.

Example 5 : HTML Builder

In this example first an HTML DOM is created before it is serialized and printed to the console. It shows how to create a builder API using extension methods and lambdas. It also demos a switch expression with type guards as an a alternative to clumsy instance-of cascades or visitors.