Ceylon is an exciting new programming language, and by new I mean it appeared in 2011 and I heard about it last week. But it is new enough that no official version has yet been released.

void hello() {  
 
    print("Hello, World!");  
 
}

The brain child of Red Hat, Ceylon promises to be “a language for writing large programs in teams”, its striking design goal being code clearly readable even by people who aren’t Ceylon programmers.

I haven’t had a chance to play with it, but all the code samples are very readable. So far so good!

In short, Ceylon is a static typed object oriented language that runs on Java and JavaScript virtual machines and introduces many interesting features from functional programming languages such as Scala.

That’s right kids, it runs in a browser.

Why’s it cool?

Ceylon

Ceylon

Leaving aside for a moment it compiles to two different intermediate codes (java bytecode and javascript) and just how astoundingly awesome that is, I also have a soft spot for anything JavaScript.

Really, though, the most striking feature is Ceylon’s type system.

First of all, there are no primitive types, everything is magically pulled out of thin air by something called principal typing. Apparently that means it can understand how types work straight from their descriptions, rather than relying on some arcane knowledge.

For every expression, a unique, most specific type may be determined, without the need to analyze the rest of the expression in which it appears. And all types used internally by the compiler are denotable - that is, they can be expressed within the language itself.

Even better than that, whatever that actually is, are union and intersection types.

Person|Organization personOrOrganization = ... ;
 
Printable&Sized&Persistent printableSizedPersistent = ... ;

You can essentially tell the compiler some value will be either a string or an integer or even both and it won’t even bat an eyelid. Add a sprinkling of local type inference and you get something very powerful indeed.

A thing can have two+ types. Strictly typed.

Let that sink in for a bit.

Now think how useful this can be when you want to have a list of items that will be of different types. Yep, pretty awesome.

There’s also typesafe null and <stuff>, known to readers of this blog as That thing Swizec can’t for the life of him understand.

String? name = ...
 
String|Nothing name = ...

This ensures we don’t get any strange NullPointerExceptions when we least want them and is essentially the same as Haskell’s Maybe monad thingy. Useful stuff :)

Another magnificent idea are polymorphic attributes.

Rather than objects having fields in the traditional sense, they have attributes. Attributes which can be pretty much anything from a simple value, to a getter-setter combination without being forced to manually define these things.

# simple value
String name = firstName + " " + lastName;
 
# getter setter pair
String name {
    return fullName;
}
 
assign name {
    fullName := name;
}

More importantly, the state of the class is completely abstracted away from whomever uses the class. Let it deal with itself.

Other things

Those are the three features that struck out when I looked through the Quick Introduction.

But there’s also a bunch of stuff we’ve come to expect from any modern language like higher order functions, comprehensions, a simple way to define tree-like structures … The latter most likely being much more powerful than I currently understand.

Most importantly, it’s not a moving target like Scala! They have milestones and after a milestone is reached they are promising no API’s and syntax and whatnot are going to change until the next milestone comes out. Very important if you ever put things in production.

Can’t wait to find an excuse to play with Ceylon.

Enhanced by Zemanta