Swizec Teller - a geek with a hatswizec.com

    Cool thing Thursday: Ceylon

    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?


    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

    Did you enjoy this article?

    Published on September 27th, 2012 in Ceylon, Functional programming, Java, JavaScript, Object-oriented programming, Red Hat, Scala, Uncategorized

    Learned something new?
    Want to become an expert?

    Here's how it works 👇

    Leave your email and I'll send you thoughtfully written emails every week about React, JavaScript, and your career. Lessons learned over 20 years in the industry working with companies ranging from tiny startups to Fortune5 behemoths.

    Join Swizec's Newsletter

    And get thoughtful letters 💌 on mindsets, tactics, and technical skills for your career. Real lessons from building production software. No bullshit.

    "Man, love your simple writing! Yours is the only newsletter I open and only blog that I give a fuck to read & scroll till the end. And wow always take away lessons with me. Inspiring! And very relatable. 👌"

    ~ Ashish Kumar

    Join over 14,000 engineers just like you already improving their careers with my letters, workshops, courses, and talks. ✌️

    Have a burning question that you think I can answer? I don't have all of the answers, but I have some! Hit me up on twitter or book a 30min ama for in-depth help.

    Ready to Stop copy pasting D3 examples and create data visualizations of your own?  Learn how to build scalable dataviz components your whole team can understand with React for Data Visualization

    Curious about Serverless and the modern backend? Check out Serverless Handbook, modern backend for the frontend engineer.

    Ready to learn how it all fits together and build a modern webapp from scratch? Learn how to launch a webapp and make your first 💰 on the side with ServerlessReact.Dev

    Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com

    By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️

    Created by Swizec with ❤️