Ceylon (programming language): Difference between revisions
No edit summary |
No edit summary |
||
Line 44: | Line 44: | ||
# do away with clumsy [[metaprogramming]] |
# do away with clumsy [[metaprogramming]] |
||
The name "Ceylon" is an oblique reference to Java, in that [[Java]] and [[Sri Lanka]], formerly known as Ceylon, are [[caffeine]] growing islands. |
The name "Ceylon" is an oblique reference to Java, in that [[Java]] and [[Sri Lanka]], formerly known as Ceylon, are [[caffeine]] growing islands. |
||
== Language features == |
== Language features == |
Revision as of 20:11, 7 February 2015
![]() | |
Paradigm | Object-oriented |
---|---|
Designed by | Gavin King, Red Hat |
First appeared | 2011 |
Stable release | 1.1.0[1]
/ October 9, 2014 |
Typing discipline | Static, strong, safe |
License | Apache v2 |
Filename extensions | .ceylon |
Website | ceylon-lang |
Influenced by | |
Java, Scala, Smalltalk |
Ceylon is an object-oriented, strongly statically typed programming language with an emphasis on immutability, created by Red Hat. It is based on the Java programming language. Ceylon programs run on the Java Virtual Machine, and can be compiled to JavaScript.[2][3]
Ceylon aims at solving the following problems its developers experienced with Java:[4][5][6]
- improved structured data and user interfaces
- language level modularity
- support for first-class and higher-order functions
- do away with clumsy metaprogramming
The name "Ceylon" is an oblique reference to Java, in that Java and Sri Lanka, formerly known as Ceylon, are caffeine growing islands.
Language features
Ceylon is heavily-influenced by Java's syntax, but adds many new features.
Type System
One of the most novel aspects of Ceylon is its type system. Ceylon foregoes java's primitive types[7] and boxing in favor of a type system comprised entirely of first-class objects.
More uniquely, Ceylon allows for union and intersection types, where a variable can have more than one type. For example, here is a Ceylon function which may take either an integer or a string:
shared void integerOrString(Integer|String input) { if (is Integer input) { print("Got the integer ``input``"); } else { print("Got the string '``input``'"); } }
An important component of this feature is flow-based typing. For example, the following code is invalid:
shared void integerOrString(Integer|String input) { Integer added = input + 6; // Illegal, we don't know that input is definitely an integer. if (is Integer input) { Integer added = input + 6; // This is fine. input can only be an integer here. print("Got the integer ``input``"); } else { print("Got the string '``input``'"); } }
The first example is wrong because the +
operator is not defined for Integer|String
, only for Integer
, but, within the else block, we have checked the type of input
and know it to be simply an Integer
, so Ceylon narrows the type of the variable input
and we can treat it like an integer.
Type Inference
Ceylon is strongly and statically typed, but also has support for type inference. For example, in most strong, statically typed languages, one would create an Integer variable with value 3 like so:
Integer foo = 3;
This is perfectly valid in Ceylon, however Ceylon also allows the following:
value foo = 3;
Here, the value
keyword indicates we are declaring a variable, but does not state its type. Instead, the type is inferred to be Integer
from our initial value of 3.
License
All the work, including the website, the language specification, and Ceylon Herd, is freely available under open source licenses.[8]
See also
- Dart (programming language), has its own VM, compiles to JS. Type system not very strict, supports mixins.
- Fantom (programming language), compiles to JVM. Type system not very strict, supports mixins.
References
- ^ King, Gavin. "Ceylon 1.1.0 is now available". Retrieved 14 October 2014.
- ^ "Ceylon 1.0 beta". Retrieved 2013-09-26.
- ^ "Project Ceylon – Red Hat builds Java replacement". The Register. 2011-04-13. Retrieved 2011-11-27.
- ^ Introducing the Ceylon Project – Gavin King presentations at QCon Beijing 2011
- ^ Gavin King (2011-04-13). "Ceylon". Retrieved 2011-11-27.
- ^ "Ceylon JVM Language". infoq.com. 2011-04-13. Retrieved 2011-11-27.
First, I never billed this as a Java Killer or the next generation of the Java language. Not my words. Ceylon isn't Java, it's a new language that's deeply influenced by Java, designed by people who are unapologetic fans of Java. Java's not dying anytime soon, so nothing's killing it
- ^ King, Gavin. "Ceylon: Language Design FAQ".
- ^ licences, official website