Swizec Teller - a geek with a hatswizec.com

Senior Mindset Book

Get promoted, earn a bigger salary, work for top companies

Senior Engineer Mindset cover
Learn more

    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?

    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.

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

    Did you enjoy this article?

    Continue reading about Cool thing Thursday: Ceylon

    Semantically similar articles hand-picked by GPT-4

    Senior Mindset Book

    Get promoted, earn a bigger salary, work for top companies

    Learn more

    Have a burning question that you think I can answer? Hit me up on twitter and I'll do my best.

    Who am I and who do I help? I'm Swizec Teller and I turn coders into engineers with "Raw and honest from the heart!" writing. No bullshit. Real insights into the career and skills of a modern software engineer.

    Want to become a true senior engineer? Take ownership, have autonomy, and be a force multiplier on your team. The Senior Engineer Mindset ebook can help 👉 swizec.com/senior-mindset. These are the shifts in mindset that unlocked my career.

    Curious about Serverless and the modern backend? Check out Serverless Handbook, for frontend engineers 👉 ServerlessHandbook.dev

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

    Want to get my best emails on JavaScript, React, Serverless, Fullstack Web, or Indie Hacking? Check out swizec.com/collections

    Did someone amazing share this letter with you? Wonderful! You can sign up for my weekly letters for software engineers on their path to greatness, here: swizec.com/blog

    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 ❤️