Ceylon (programming language)

Ceylon is an object-oriented programming language , developed by Red Hat . The language itself takes a lot of its Java Programming Language syntax . It is static typed and with type inference that runs on top of the Java virtual machine or can also compile to JavaScript. This language has been created by Gavin King , creator of Hibernate . The purpose of Ceylon is to improve deficiencies of Java, although at the same time it pretends not to be exclusive of it; They also have code written in Java and JavaScript .

Summary

[ hide ]

  • 1 Features
  • 2 Ceylon Objectives
  • 3 Design philosophy
  • 4 Types of data in Ceylon
  • 5 Class of Ceylon
  • 6 Recognizing Java weaknesses
  • 7 Leveraging tools
  • 8 References

characteristics

Ceylon, a static type language that maintains some of the best Java language devices (and runs in the JVM) but improves the readability of that language, built-in modularity, and the incorporation of functional language devices such as higher order functions. Ceylon also incorporates C and Smalltalk devices. Like the Java language, that new language focuses on business computing, but it is also flexible and useful in other areas.

Some call Ceylon a “Java killer” (perhaps due to doubts about the future of the Java language) but in reality Ceylon runs on the JVM, therefore it is not a replacement, but an extension of Java technology. Using the JVM to support running Ceylon is an ideal model, as it means that Ceylon (like Java) is portable across a wide variety of architectures that currently support the JVM.

Most of today’s languages ​​defy simple categorization and instead represent a variety of programming styles. Ceylon is no different. It is a static type language (that is, type checking occurs at compile time, differently from dynamic type languages ​​like Lisp, in which type checking is done at runtime). Ceylon is an object-oriented language, like the Java language, and it also supports higher-order functions (meaning that functions can take functions as input or output) with a typical C syntax style. Higher-order functions do not they are directly supported in the Java language; therefore, this functionality represents an exclusive difference in the two languages.

However, sometimes improvements have more to do with what a language removes, and not what it adds. Ceylon simplifies and eliminates elements of the Java language, replacing them with a simpler scheme. An example of simplification is removing the public, protected and private keywords. Instead, Ceylon simply includes the shared annotation, which defines the elements of a class that are externally visible. Ceylon also eliminates the ability to overload, but provides some alternate workarounds for that functionality (such as parameters with default and sequenced values) with simpler syntax.

Includes support for inheritance, sequences (array or list construction), generics, named arguments, etc. Includes devices for type management at runtime. The language is in active development, therefore the final set of devices is still open.

Ceylon Objectives

  • Be easy to learn for both Java and C # developers.
  • Eliminate Java verbosity while maintaining readability.
  • Improve static typing of Java.
  • Provide a declarative expression to remove dependencies with xml.
  • Support and encourage a more functional programming style.
  • Provide support for meta-programming.
  • Provide modular construction.

Design philosophy

Ceylon’s design principles do not revolve around technological capabilities (eg, concurrency, garbage collection) but rather on how software projects work, especially large-scale business software. Here are some of the characteristics of this type of project:

  • They are large systems, measured in the order of tens of thousands of lines of code.
  • The teams of members are large (more than 10 people), diverse, geographically distributed and with high turnover.
  • Once released for production, the systems require a high degree of maintenance to incorporate changes and improvements. And most likely, the people in charge of doing this are a different group than those who developed it.

That is why the fundamental design principles of Ceylon are:

  • Readability. The code in Ceylon seeks to be highly readable and easy to understand by third parties. Ceylon does not focus purely on having a syntax neither brief nor elaborate, but easy to understand.
  • Predictability. When there are compilation or runtime errors, they should be easy to understand and trace back to their root cause.

Ceylon data types

Ceylon incorporates a traditional set of types that are implemented as ordinary classes. Those guys are:

  • Unsigned integers, including zero
  • Signed integers
  • Floating point
  • Integers signed with arbitrary precision
  • Decimals with arbitrary scale and precision

By default, the Natural, Integer, and Float types are 64-bit, but you can annotate them with small to specify 32-bit precision.

Ceylon class

Since Ceylon is an object-oriented language, write code with the concept of classes. A class is a type in Ceylon that encapsulates a set of operations (called methods) and also declares a definition of how the state is initialized when an object of the class is initialized (the class initializer, similar to the constructor).

A simple class will help understand Ceylon’s approach. the class is defined with an optional value, which means that the user can provide it or not, and is denoted with the Type? pattern. Instead of a constructor, the body of the class contains the class initializer. That code defines the private variable (nothing is visible unless it is annotated as shared) and then the initialization logic. It begins by checking if the initial variable exists. If it exists, it is used as the starting value for your count. Its first method, annotated as shared and therefore externally visible from the class, defines the incrementor. When called, that method simply increments its counter.

Finally, a getter method is defined that returns the current value of the counter for the user and a setter method that defines the current value of the counter with a value provided by the caller. Note the use of the assign keyword here to create a variable attribute to define the value of the counter. Other than manipulating constructors differently (code built into the class), there is no deconstructor and there is no way to implement multiple constructors (just one of the differences from the Java language).

01 doc “Simple Counting Class”

02 class Counter (Natural? Start) {

03

04 doc “Class Initializer”

05 Natural count variable: = 0;

06 if (exists start) {

07 count: = start;

09}

10

11 doc “The incrementer”

12 shared void increment () {

13 count ++;

14}

fifteen

16 doc “The getter”

17 shared Natural currentValue {

18 return count;

19}

twenty

21 doc “The setter”

22 shared assign currentValue {

23 count: = currentValue;

24}

25

26}

With the simple class defined, let’s see how to use it. Below is a code block that uses the Counter class. It begins with the instantiation of the class of the cnt object. Notice that there is no new keyword in Ceylon. With your new Counter object defined, you call the increment method and then output the Counter value using your getter method. Note that the = and: = operators are different in Ceylon: the = specifier is used only for immutable values, while the assignment of variables is done with the operator : =

01 Counter cnt = Counter (1);

02 cnt.increment ();

03 writeLine (c.currentValue);

Ceylon encourages the use of immutable attributes whenever possible. That means that an object is initialized with a value and not reassigned.

Java weaknesses recognition

Although Ceylon tries to take advantage of Java’s strengths, it also recognizes its weaknesses and seeks to learn how other languages ​​do things better. An example is the case of modularity. Modularity (or lack of) has always been one of Java’s weak points. Why do we have to install the full JRE to run a “hello world”? Ceylon recognizes the beauty / simplicity of using gems in Ruby, or packages in Node, and incorporates something similar.

Leveraging tools

Ceylon is a statically typed language. These types of languages ​​typically require more lines of code than dynamic languages, and therefore can be considered less productive. This may be true when you program everything manually from a text editor, but when you rely on modern development environments, using static typing becomes more of an advantage than a disadvantage. Since the tools can better understand your code, they can help you more with it: generating, debugging, and testing it. And this also extends to the use of libraries and frameworks. Another advantage of using static typing is being able to detect errors from compilation, and not until execution.

 

Leave a Comment

Scroll to Top