Xtend

Last updated
Xtend
Xtend-logo-c.png
Paradigm Object-oriented, imperative, functional
Designed by Sven Efftinge, Sebastian Zarnekow
Developer typefox
First appeared2011
Stable release
2.25.0 / March 2, 2021;2 years ago (2021-03-02) [1]
Typing discipline Static, strong, inferred
Platform Java Virtual Machine
OS Cross-platform
License Eclipse Public License
Website eclipse.dev/Xtext/xtend/
Influenced by
Java, Scala, Groovy, Smalltalk, Xpand

Xtend is a general-purpose high-level programming language for the Java Virtual Machine. Syntactically and semantically Xtend has its roots in the Java programming language but focuses on a more concise syntax and some additional functionality such as type inference, extension methods, and operator overloading. Being primarily an object-oriented language, it also integrates features known from functional programming, e.g. lambda expressions. Xtend is statically typed and uses Java's type system without modifications. It is compiled to Java code and thereby seamlessly integrates with all existing Java libraries.

Contents

The language Xtend and its IDE is developed as a project at Eclipse.org [2] and participates in the annual Eclipse release train. The code is open source under the Eclipse Public License. Yet, the language can be compiled and run independently of the Eclipse platform.

History

Xtend originated from Xtext, which is the technology used to define the language and the editor. Xtend was first released as part of Xtext in the Eclipse release Indigo [3] in June 2011. Since the Eclipse release Juno [4] (June 2012, Xtend version 2.3) Xtend has become a standalone project.

The language Xtend described here should not be confused with the older language with the same name in the Xpand [5] project. Initially, Xtend was named Xtend2 for better distinction. The '2' was dropped soon for simplicity. With its template expressions, Xtend is meant as a replacement of the entire Xpand technology.

Philosophy

Java is one of the most popular programming languages ever with a large ecosystem of libraries and tools. Yet, its syntax is considered verbose by some, and some concepts are missing and only added slowly. Xtend tries to get the best of Java, but reduce syntactic noise and add new features to allow for shorter and better readable code.

To make it easier to learn for Java developers, Xtend's syntax is close to Java's. Xtend maintains maximum compatibility with Java by compiling to Java code and using Java's type system. Java code and Xtend code can be mixed inside the same project at will.

Using a combination of lambda expressions and extension methods, the language can be extended by means of libraries, i.e. without changing the language itself. A small standard library makes heavy use of this.

The Eclipse-based Xtend IDE offers syntax highlighting, code completion, refactoring, navigation and debugging. It integrates with Eclipse's Java Development Toolkit. [6]

Semantics

Xtend resembles Java in many regards. Here is an example Xtend file:

packagesampleimportjava.util.ListclassGreeter{defgreetThem(List<String>names){for(name:names){println(name.sayHello)}}defsayHello(Stringname){'Hello '+name+'!'}}

Xtend provides type inference, i.e. the type of name and the return types of the methods can be inferred from the context. Classes and methods are public by default, fields private. Semicolons are optional.

The example also shows the method sayHello called as an extension method, i.e. like a feature of its first argument. Extension methods can also be provided by other classes or instances.

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

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

Note that the lambda's parameter, if not specified, is called it, which can be skipped like this in Java. Its type is inferred as string. Lambda expressions are also automatically coerced to single method interfaces, such that they can be passed e.g. as a java.lang.Comparable.

Template expressions are multi-line strings within triple quotes with interpolated values in French quotes. In the example above one could write

defsayHello(Stringname)'''    Hello «name» !'''

Xtend offers intelligent white-space management - the above text will not be indented in the output - thus meeting the requirements of code generation.

Further language features include multimethods, a powerful switch expression, and operator overloading by means of library methods.

Related Research Articles

<span class="mw-page-title-main">PHP</span> Scripting language created in 1994

PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. PHP was originally an abbreviation of Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor.

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

In object-oriented programming languages, a mixin is a class that contains methods for use by other classes without having to be the parent class of those other classes. How those other classes gain access to the mixin's methods depends on the language. Mixins are sometimes described as being "included" rather than "inherited".

<span class="mw-page-title-main">Apache Groovy</span> Programming language

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.

<span class="mw-page-title-main">Foreach loop</span> Control flow statement for traversing items in a collection

In computer programming, foreach loop is a control flow statement for traversing items in a collection. foreach is usually used in place of a standard for loop statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This avoids potential off-by-one errors and makes code simpler to read. In object-oriented languages, an iterator, even if implicit, is often used as the means of traversal.

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

E is an object-oriented programming language for secure distributed computing, created by Mark S. Miller, Dan Bornstein, Douglas Crockford, Chip Morningstar and others at Electric Communities in 1997. E is mainly descended from the concurrent language Joule and from Original-E, a set of extensions to Java for secure distributed programming. E combines message-based computation with Java-like syntax. A concurrency model based on event loops and promises ensures that deadlock can never occur.

In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.

<span class="mw-page-title-main">Scala (programming language)</span> General-purpose programming language

Scala is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are intended to address criticisms of Java.

String functions are used in computer programming languages to manipulate a string or query information about a string.

<span class="mw-page-title-main">Python syntax and semantics</span> Set of rules defining correctly structured programs

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. It supports multiple programming paradigms, including structured, object-oriented programming, and functional programming, and boasts a dynamic type system and automatic memory management.

In computer programming, an anonymous function is a function definition that is not bound to an identifier. Anonymous functions are often arguments being passed to higher-order functions or used for constructing the result of a higher-order function that needs to return a function. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function. Anonymous functions are ubiquitous in functional programming languages and other languages with first-class functions, where they fulfil the same role for the function type as literals do for other data types.

Cobra is a discontinued general-purpose, object-oriented programming language. Cobra is designed by Charles Esterbrook, and runs on the Microsoft .NET and Mono platforms. It is strongly influenced by Python, C#, Eiffel, Objective-C, and other programming languages. It supports both static and dynamic typing. It has support for unit tests and contracts. It has lambda expressions, closures, list comprehensions, and generators.

OptimJ is an extension for Java with language support for writing optimization models and abstractions for bulk data processing. The extensions and the proprietary product implementing the extensions were developed by Ateji which went out of business in September 2011. OptimJ aims at providing a clear and concise algebraic notation for optimization modeling, removing compatibility barriers between optimization modeling and application programming tools, and bringing software engineering techniques such as object-orientation and modern IDE support to optimization experts.

Nemerle is a general-purpose, high-level, statically typed programming language designed for platforms using the Common Language Infrastructure (.NET/Mono). It offers functional, object-oriented, aspect-oriented, reflective and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system.

In computer programming, string interpolation is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values. It is a form of simple template processing or, in formal terms, a form of quasi-quotation. The placeholder may be a variable name, or in some languages an arbitrary expression, in either case evaluated in the current context.

Xtext is an open-source software framework for developing programming languages and domain-specific languages (DSLs). Unlike standard parser generators, Xtext generates not only a parser, but also a class model for the abstract syntax tree, as well as providing a fully featured, customizable Eclipse-based IDE.

Kotlin is a cross-platform, statically typed, general-purpose high-level programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code via LLVM. Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.

In certain computer programming languages, the Elvis operator, often written ?:, is a binary operator that returns its first operand if that operand evaluates to a true value, and otherwise evaluates and returns its second operand. This is identical to a short-circuit or with "last value" semantics. The notation of the Elvis operator was inspired by the ternary conditional operator, ? :, since the Elvis operator expression A ?: B is approximately equivalent to the ternary conditional A ? A : B.

In object-oriented programming, the safe navigation operator is a binary operator that returns null if its first argument is null; otherwise it performs a dereferencing operation as specified by the second argument.

References

  1. "Xtend - Release Notes". eclipse.org. Retrieved 2021-04-05.
  2. Sven Efftinge. "Official Xtend Homepage at". Eclipse.org. Retrieved 2013-09-14.
  3. "Eclipse Indigo release". Wiki.eclipse.org. 2011-03-30. Retrieved 2013-09-14.
  4. "Eclipse Juno release". Wiki.eclipse.org. 2012-03-17. Retrieved 2013-09-14.
  5. "Xpand". Wiki.eclipse.org. 2013-06-04. Retrieved 2013-09-14.
  6. "JDT". Eclipse.org. Retrieved 2013-09-14.

Bibliography