Ceylon - the language and its tools


Published on

Ceylon is a new programming language for the JVM which was recently released on http://ceylon-lang.org with Eclipse based tooling available from day one.

This talk will introduce you to the goals and some of the features of the language while showing the features of the Eclipse based IDE.

Ceylon is a programming language for writing large programs in a team environment. The language is elegant, highly readable, extremely typesafe, and makes it easy to get things done. And it's easy to learn for programmers who are familiar with mainstream languages used in business computing. Ceylon has a full-featured Eclipse-based development environment, allowing developers to take best advantage of the powerful static type system. Programs written in Ceylon execute on the JVM.

Slides as they were used at EclipseCon 2012

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • JBoss: Emmanuel, Pete Muir, David Lloyd, Ales Justin, and more...\n\n\n
  • \n
  • simple class, should be nice and familiar.\nA few rules: classes always starts with a capital letter, and methods/attributes always starts with a lowercase letter.\n\nThe doc is a string/annotation to help \narea is a function using type inference.\n\nBut where is the constructor ?\n
  • constructor in the blocks\n\nThe area now have to be explicit about its type to avoid exposing too specific types.\n\nstarting to use shared for scope/visibility.\n\n\n
  • shared is the only scope modifier.\nmodule, package, class/methods\n\nshared are seen by those within my parent and outside if parent is shared too.\nYou can talk to the kids if you also can see the parents.\n\nTo be public you really need to mean it\n
  • To have mutable data you really need to mean it.\n
  • variable properties with values and methods (badArea)\n\n\n
  • class extends - parameters passed into the class constructor.\n
  • Ceylon is extremely regular - everything can be nested, allowing a lot more modularity than we are used to in java.\n
  • There is no way ceylon code can get an NPE. Its checked by the compiler and if you must you use if exists or the elvis operator ?.\n\n
  • One of the exotic but key features of Ceylon is its type system - it is after all a strongly typed language. \n\n
  • You are used to having a variable just having “one type” but in Ceylon they can actually be representing multiple types all at the same time.\n\n
  • Notice that I can call shared methods on union types - such as food.string.\nIf I tried to call food.eat() before it would not let me. \n
  • Here Guiness is both a food and drink and thus I can call both Food and Drink methods - but I can’t assign just a Food.\n
  • \n
  • \n
  • \n
  • \n
  • Just one rectangle constructor/method - all handled with default parameters.\n\nYou can use named parameters too.\n
  • use type switch for handling visitor patterns and similar type based ‘overloading’\n\n\n\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Ceylon - the language and its tools

    1. 1. the language and its tools Max Rydahl Andersen Red Hat http://about.me/maxandersen EclipseCon 2012
    2. 2. About Me• Max Rydahl Andersen• Lead of JBoss Tools & Developer Studio• Committer on Hibernate Core, Seam & Weld• Co-host of JBoss Community Asylum Podcast• @maxandersen on Twitter• http://about.me/maxandersen
    3. 3. Ceylon Origins• Created and lead by Gavin King• Helped by others at JBoss• Frustrated love for Java• Lessons learned working in JCP• Starting blocks • on the JVM • in the spirit of Java • practical• Slashdotted (with no web site)
    4. 4. Language Introduction z
    5. 5. doc "A familiar Rectangle"class SimpleRectangle() { Integer width = 0; Integer height = 0; function area() { return width * height; }}
    6. 6. doc "A real Rectangle."shared class Rectangle(Integer width, Integerheight) { // initializer if(width <=0 || height <=0) { throw; } shared Integer width = width; shared Integer height = height; shared Integer area() { return width * height; } }
    7. 7. Modular by defaultpackage com.acme.dotcom.domain package com.acme.dotcom.businessshared class Foo class Woo shared class Action class Reactionshared String bar() shared String war() shared String ping() String pong() String baz() String waz()
    8. 8. Immutable by defaultInteger width = w;
    9. 9. Immutable by defaultInteger width = w; variable Integer width := w;
    10. 10. doc "A variable Rectangle with properties."shared class VariableRectangle(Integer w,Integer h) { shared variable Integer width := w; shared variable Integer height := h; shared Integer badArea { return width * 42; } Text assign badArea { width := badArea/42; } shared actual String string { return "w:" width ",h:" height ""; }}
    11. 11. shared classPoint(Integer x, Integer y) { shared Integer x = x; shared Integer y = y;}shared classPoint3D (Integer x, Integer y, Integer z) extends Point(x, y) { shared Integer z = z;}
    12. 12. Integer attribute = 1;Integer attribute2 { return 2; }void topmethod(){}interface Interface{}class Class(Integer x){ Integer attribute = x; Integer attribute2 { return x; } class InnerClass(){} interface InnerInterface{} void method(Integer y){ Integer attribute = x; Integer attribute2 { return y; } class LocalClass(){} interface LocalInterface{} void innerMethod(Integer y){} }}
    13. 13. No NullPointerException’svoid typesafety() { Rectangle? rectOrNoRect() { return null; } Rectangle? rect = rectOrNoRect(); print(rect.string); // compile error if(exists rect) { print(rect.string); } else { print("No rectangle"); }}
    14. 14. What is in a Type ?
    15. 15. Union Type• To be able to hold values among a list of types• We must check the actual type before use• `TypeA|TypeB`• `Type?` is an alias for `Type|Nothing`
    16. 16. class Apple(){ shared void eat() { print("Eat " this ""); }}class Broccoli(){ shared void throwAway() { print("Throw " this ""); } }void unions() { Sequence<Apple|Broccoli> plate = {Apple(), Broccoli()}; for (Apple|Broccoli food in plate) { print("Looking at: " food.string ""); if (is Apple food) { food.eat(); } else if (is Broccoli food) { food.throwAway(); } }}
    17. 17. Intersection Typeinterface Food { shared formal void eat(); }interface Drink { shared formal void drink(); }class Guinness() satisfies Food & Drink { shared actual void drink() {} shared actual void eat() {}}void intersections(){ Food & Drink specialStuff = Guinness(); specialStuff.drink(); specialStuff.eat();}
    18. 18. No Overloading
    19. 19. No Overloading • WTF!?
    20. 20. No Overloading • WTF!? • is overloading evil ?
    21. 21. No Overloading • WTF!? • is overloading evil ?
    22. 22. No Overloading • WTF!? • is overloading evil ? • Only usecase: • Optional parameters • Work on different subtypes
    23. 23. classRectangle(Integer width = 2, Integer height = 3) { shared Integer area(){ return width * height; }}void method() { Rectangle rectangle = Rectangle(); Rectangle rectangle2 = Rectangle { width = 3; height = 4; };}
    24. 24. interface Shape2D of Triangle|Circle|Figure2D {}class Triangle() satisfies Shape2D {}class Circle() satisfies Shape2D {}class Figure2D() satisfies Shape2D {}void workWithRectangle(Triangle rect){}void workWithCircle(Circle circle){}void workWithFigure2D(Figure2D fig){}void supportsSubTyping(Shape2D fig) { switch(fig) case(is Triangle) { workWithRectangle(fig); } case(is Circle) { workWithCircle(fig); } case(is Figure2D) { workWithFigure2D(fig); }}
    25. 25. Other features• Interface based Operator overloading• Closures• Annotations• Type aliases• Meta-model• Interception• Interface with default implementations / “multiple inheritance”• Declarative syntax for datastructures• ...and more
    26. 26. Table table = Table { title="Squares"; rows=5; border = Border { padding=2; weight=1; }; Column { heading="x"; width=10; String content(Natural row) { return row.string; } }, Column { heading="x**2"; width=12; String content(Natural row) { return (row**2).string; } }};
    27. 27. Ceylon Today• Website (http://ceylon-lang.org)• Active and growing community• Fully open source (http://github.com/ceylon)• Targets JVM and JS (http://try.ceylon-lang.org)• Milestone 2 just released • Java interopability • Full IDE support
    28. 28. Ceylon IDE
    29. 29. Ceylon IDE• Incremental compiler and error reporting• Full editor with outline, folding and navigation• Refactoring, Quick fixes, Search• Wizards, Module repository integration• Debugging
    30. 30. Ceylon IDE - Behind the Scenes• Considered XText, DLTK, IMP & “DIY”• XText - very complete, but does not allow Antlr and require XText custom parser and typechecker• DLTK - allows Antlr, but at the time no good documentation and a preference to by “too dynamic language focused”• IMP - allows antlr and custom typechecker and just worked, but..
    31. 31. Ceylon IDE - Next Steps• IMP has many limitations when you push it• XText still too much “XText”• DLTK looks interesting• End result probably a mix of the above in a “DIY” solution• Contributors welcome!
    32. 32. Ceylon - Tomorrow• M3: • - Annotations • - Reified type parameters • - Interception • - Meta-model • <Your Name Here>
    33. 33. ?• http://try.ceylon-lang.org• http://ceylon-lang.org• http://ceylon.github.com/ Text Text bit.ly/ec12ceylon