Xtend

from Wikipedia, the free encyclopedia
Xtend
Paradigms : object-oriented , imperative , functional
Publishing year: 2011
Designer: Sven Efftinge, Sebastian Zarnekow
Developer: itemis
Current  version 2.19.0
Typing : strong , static
Influenced by: Java , Scala , Groovy , Smalltalk , Xpand
Operating system : platform independent
License : Eclipse Public License
www.xtend-lang.org

Xtend is a programming language for the Java Virtual Machine . Syntactically and semantically, Xtend has its roots in the Java programming language . However, the focus is on a more compact syntax and additional functionality such as type inference , extension methods and operator overloading . Xtend is primarily object-oriented , but also enables functional programming , e.g. B. by lambda expressions . Xtend is statically typed and uses the Java type system without changes. It is compiled on Java source code and therefore integrates seamlessly with existing Java libraries.

The Xtend language and its development environment are developed in the Eclipse project and take part in the annual simultaneous release. The code is available open source under the Eclipse Public License . Nevertheless, the language can be compiled and executed independently of the Eclipse project.

history

Xtend originally comes from the Xtext project, with which the language and the editor are developed. Xtend was therefore initially published as part of Xtext in the Eclipse release Indigo in June 2011. Since the Eclipse release Juno (June 2012, Xtend version 2.3), Xtend has been an independent project. On March 20, 2013, Xtend version 2.4.0 was released with extended features such as "Active Annotations ".

The Xtend language described here should not be confused with the older language of the same name from the Xpand project. In order to avoid misunderstandings, Xtend was therefore initially called Xtend2 . The '2' was soon left out for the sake of simplicity. Thanks to its template expressions, Xtend completely replaces the Xpand technology.

philosophy

Java is one of the most popular programming languages ​​and there is an extensive ecosystem of libraries and tools. Still, the syntax is often found to be bulky and new properties are slowly added. Xtend tries to get the best of Java, but tries to improve the syntax and add features to enable more readable, more expressive code.

Xtend's syntax is closely related to Java and is compatible with Java, since Xtend code is compiled to Java source code and Java's type system is used unchanged. Java code and Xtend code can therefore be used side by side. A combination of lambda expressions and extension methods allows Java to be extended with libraries without having to adapt the language definition.

The Eclipse-based Xtend IDE offers, among other things, syntactic highlighting, code completion, refactoring, navigation and debugging. It also integrates with Eclipse's Java Development Toolkit.

semantics

Xtend is similar to Java in many ways, as the following Xtend example shows:

package sample

import java.util.List

class Greeter {
  def greetThem(List<String> names) {
    for(name: names) {
      println(name.sayHello)
    }
  }

  def sayHello(String name) {
    'Hello ' + name + '!'
  }
}

Xtend offers type inference , that is, the types of nameand the return types of the methods can be inferred from the context. By default public, classes and methods are member variables private. Semicolons are optional.

In the example, the method is sayHellocalled as an extension method , i.e. like a method of the first argument name. Extension methods can also be contributed by other classes or instances.

Instead of the imperative for loop, you can also use a lambda expression in square brackets in the functional style and call the higher-order function forEach in extension syntax on the list:

def greetThem(List<String> names) {
  names.forEach [ println(sayHello) ]
}

If the parameter of a lambda expression is not specified, its name is implicitly itassumed, which thiscan be omitted as in Java. His type is inferred. Lambda expressions are also automatically converted into interfaces of a method so that they can be used as, for example java.lang.Comparable.

Template expressions are multiline strings in triple apostrophes with interpolated expressions in French quotation marks . The above example would look like this with a template expression:

def sayHello(String name) '''
    Hello «name» !
'''

Template expressions have intelligent space management - the text in the example is not indented - and are therefore very suitable for code generation.

Other notable language features are multi-methods , an extended switch statement and operator overloading with library methods.

Web links

  • Sven Efftinge, Sebastian Zarnekow: Extending Java . In: Pragmatic Programmer Magazine , December 2011.
  • Alex Blewitt: Xtend Extends Java . In: InfoQ , June 2012; Interview with Sven Efftinge.

literature

  • Lorenzo Bettini, Implementing Domain-Specific Languages ​​with Xtext and Xtend - Second Edition, Packt Publishing, 2016

Individual evidence

  1. Xtend - Release Notes . September 2, 2019 (accessed November 7, 2019).
  2. Official Xtend homepage on Eclipse.org
  3. Eclipse Indigo release
  4. Eclipse Juno release
  5. Xtend 2.4 Release Notes ( Memento from April 8, 2013 in the Internet Archive )
  6. Xtend 2.4 Release Notes
  7. Xpand
  8. JDT