HOME

TheInfoList



OR:

Xtend is a general-purpose
high-level programming language In computer science, a high-level programming language is a programming language with strong Abstraction (computer science), abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ...
for the
Java Virtual Machine A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
. Syntactically and semantically Xtend has its roots in the
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
programming language but focuses on a more concise syntax and some additional functionality such as
type inference Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistics ...
,
extension method In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-orie ...
s, and
operator overloading In computer programming, operator overloading, sometimes termed ''operator ad hoc polymorphism'', is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is ...
. Being primarily an
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
language, it also integrates features known from
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declar ...
, e.g.
lambda expressions Lambda expression may refer to: *Lambda expression in computer programming, also called an anonymous function In computer programming, an anonymous function (function literal, lambda abstraction, lambda function, lambda expression or block) is a f ...
. Xtend is
statically typed In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
and uses Java's
type system In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
without modifications. It is compiled to
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
code and thereby seamlessly integrates with all existing Java libraries. The language Xtend and its IDE is developed as a project at Eclipse.org and participates in the annual Eclipse release train. The code is open source under the
Eclipse Public License The Eclipse Public License (EPL) is a free and open source software license most notably used for the Eclipse IDE and other projects by the Eclipse Foundation. It replaces the Common Public License (CPL) and removes certain terms relating to ...
. Yet, the language can be compiled and run independently of the Eclipse platform.


History

Xtend originated from
Xtext 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 ...
, which is the technology used to define the language and the editor. Xtend was first released as part of
Xtext 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 ...
in the Eclipse release ''Indigo'' in June 2011. Since the Eclipse release ''Juno'' (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 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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, but reduce syntactic noise and add new features to allow for shorter and better readable code. To make it easier to learn for
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
developers, Xtend's syntax is close to
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
's. Xtend maintains maximum compatibility with
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
by compiling to
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
code and using
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
's type system.
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
code and Xtend code can be mixed inside the same project at will. Using a combination of
lambda expressions Lambda expression may refer to: *Lambda expression in computer programming, also called an anonymous function In computer programming, an anonymous function (function literal, lambda abstraction, lambda function, lambda expression or block) is a f ...
and
extension methods In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-orie ...
, 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.


Semantics

Xtend resembles
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
in many regards. Here is an example Xtend file: package sample import java.util.List class Greeter Xtend provides
type inference Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistics ...
, 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 In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-orie ...
, i.e. like a feature of its first argument.
Extension methods In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-orie ...
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 In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following: * takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itself ...
forEach in extension syntax on the list: def greetThem(List names) 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 def sayHello(String name) 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 Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run-time (dynamic) type or, in the more general case, some other attribute of more than one of ...
, a powerful switch expression, and
operator overloading In computer programming, operator overloading, sometimes termed ''operator ad hoc polymorphism'', is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is ...
by means of library methods.


References

{{Reflist


Bibliography

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


External links

* Sven Efftinge, Sebastian Zarnekow
Extending Java
Pragmatic Programmer Magazine, Dec 2011. * Alex Blewitt
Xtend Extends Java
Interview with Sven Efftinge, InfoQ, Jun 2012. Eclipse (software) JVM programming languages Software using the Eclipse license Programming languages created in 2011