Ceylon - the language and its tools
Upcoming SlideShare
Loading in...5
×
 

Ceylon - the language and its tools

on

  • 1,227 views

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. ...

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

Statistics

Views

Total Views
1,227
Views on SlideShare
1,227
Embed Views
0

Actions

Likes
0
Downloads
39
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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 Ceylon - the language and its tools Presentation Transcript

  • the language and its tools Max Rydahl Andersen Red Hat http://about.me/maxandersen EclipseCon 2012
  • 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
  • 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)
  • Language Introduction z
  • doc "A familiar Rectangle"class SimpleRectangle() { Integer width = 0; Integer height = 0; function area() { return width * height; }}
  • 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; } }
  • 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()
  • Immutable by defaultInteger width = w;
  • Immutable by defaultInteger width = w; variable Integer width := w;
  • 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 ""; }}
  • 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;}
  • 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){} }}
  • 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"); }}
  • What is in a Type ?
  • 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`
  • 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(); } }}
  • 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();}
  • No Overloading
  • No Overloading • WTF!?
  • No Overloading • WTF!? • is overloading evil ?
  • No Overloading • WTF!? • is overloading evil ?
  • No Overloading • WTF!? • is overloading evil ? • Only usecase: • Optional parameters • Work on different subtypes
  • 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; };}
  • 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); }}
  • 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
  • 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; } }};
  • 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
  • Ceylon IDE
  • Ceylon IDE• Incremental compiler and error reporting• Full editor with outline, folding and navigation• Refactoring, Quick fixes, Search• Wizards, Module repository integration• Debugging
  • 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..
  • 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!
  • Ceylon - Tomorrow• M3: • - Annotations • - Reified type parameters • - Interception • - Meta-model • <Your Name Here>
  • ?• http://try.ceylon-lang.org• http://ceylon-lang.org• http://ceylon.github.com/ Text Text bit.ly/ec12ceylon