Documente Academic
Documente Profesional
Documente Cultură
Executive summary
What is Ceylon Why Ceylon Features and feel Demo The community Status
Origins o Ceylon
5nitiated and led %y 2a/in 6in7 5mpro/e upon frustrations of 0a/a
!hat is Ceylon"
Ceylon is "o8erful reada%le predicta%le Ceylon has 9 platform modularity toolin7
Introduction to Ceylon
A boring class
:oo;s familiar ri7ht<
class Rectangle() { Integer width = 0; Integer height = 0; Integer area() { return width * height; } }
8
=o ,%i7- surprise
shared class Rectangle(width, height) { shared Integer width; shared Integer height; shared Integer area() { return width * height; } }
!here is my constructor"
5n the class %ody
shared class Rectangle(width, height) { shared Integer width; shared Integer height; // it is here! if (width == 0 || height == 0) { throw Exception(); } shared Integer area() { return width * height; } }
1 0
#irst di erences
Simpler and more re7ular access rules
=o >protected> >pac;a7e> >pri/ate> >shared> ? pu%lic-ish other8ise scope-pri/ate
1 1
Attributes
5mmuta%le %y default
class Circle() { Integer scale = 1; variable Integer radius := 2; radius++; Integer diameter { return radius * 2; } assign diameter { radius := diameter / 2; } }
1 2
Attributes
1nless mar;ed /aria%le 9ssi7ned 8ith 3? class Circle() { Integer scale = 1; variable Integer radius := 2; radius++; Integer diameter { return radius * 2; } assign diameter { radius := diameter / 2; } }
1 3
Attributes
2etter4setter 8ithout carpal tunnel syndrome
class Circle() { Integer scale = 1; variable Integer radius := 2; radius++; Integer diameter { return radius * 2; } assign diameter { radius := diameter / 2; } }
1 4
Inheritance
shared class Point(x, y) { shared Integer x; shared Integer y; } shared class Point3D(Integer x, Integer y, z) extends Point(x, y) { shared Integer z; }
1 5
Abstractions
)ethod attri%utes and classes can %e o/erridden
Factory pattern
Abstractions $example%
abstract class Shape() { shared formal Integer area(); // magic: this is toString() shared actual default String string { return "Abstract area: " area.string " m2"; } } class Square(Integer width) extends Shape() { shared actual Integer area() { return width * width; } shared actual String string = "Square area: " area.string " m2"; }
1 7
Overloading
=o O/erloadin7
WTF#<
O/erloadin7 is e/il
1 8
1 9
(eeping it )R&
interface Figure3D { shared formal Float area; shared formal Float depth; shared formal Float volume; } class Cube(Float width) shared actual Float shared actual Float shared actual Float } satisfies Figure3D { area = width * width; depth = width; volume = area * depth;
class Cylinder(Integer radius, depth) satisfies Figure3D { shared actual Float area = 3.14 * radius ** 2; shared actual Float depth = depth; shared actual Float volume = area * depth; }
2 2
2 3
2 4
Hierarchical structure
15
Table table = Table { title = "Squares"; rows = 5; border = Border { padding = 2; weight = 1; }; Column { heading = "x"; width = 10; String content(Integer row) { return row.string; } }, Column { heading = "x**2"; width = 12; String content(Integer row) { return (row**2).string; } } };
2 6
Semantics ./.01
2 8
2ust (idding-
3ypical types
Integer n = 10.times(2); // no primitive types String[] s = {"foo", "bar"}; // inference Number[] r = 1..2; // intervals // inference function makeCube(Float width){ return Cube(width); } value cube2 = makeCube(3.0);
3 0
)eath to 45Es
3 1
3ype sa ely
// optional? Cube? cubeOrNoCube() { return null; } Cube? cube = cubeOrNoCube(); print(cube.area.string); // compile error if(exists cube) { print(cube.area.string); } else { print("Got no cube"); }
3 2
3 3
Operations on lists
Integer[] numbers = {1,2,3}; // slices Integer[] subList = numbers[1..2]; Integer[] rest = numbers[1...]; // map/spread Integer[] successors = numbers[].successor; Integer[] shifted = numbers[].minus(2);
3 4
#unctional programming
// using closures (FP-style) value urls = projectMap.keys .filter(function(String key) key.contains(url)) .map(function(String key) projectMap[key]); // using comprehensions (Imperative-style) value urls2 = { for(key in projectMap.keys) if(key.contains(url)) projectMap[key] };
3 5
$some o % 3yping
6nion type
To %e a%le to hold /alues amon7 a list of types We must chec; the actual type %efore use >Type9DTypeE> >Type<> is an alias for >TypeD=othin7>
3 7
Intersection type
interface 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(); }
3 9
4 0
+odularity
Herd
Our ne!t-7en module repo On http344modules$ceylon-lan7$or7
9lready a/aila%le and usa%le from the tools
Free Soft8are
"ri/ate repos encoura7ed
)emo -
Community
Completely open Some from 0Eoss4Red.at 9nd ,/ery- acti/e contri%utors From all o/er 9nd you#
4 4
A un pro7ect
=ice people 3 Eest tools
7ithu% ant Eclipse .T):G 98estruct 0a/a 0a/aScript OpenShift "lay#
)any su%projects
spec typechec;er 0H) compiler 0a/aScript compiler Eclipse 5DE We% 5DE SD6 .erd module system ceylondoc 9nt4)a/en plu7ins C:5 plu7ins
3he roadmap
Si! milestones to reach '$+ Some features tar7eted to '$'
4 6
3o in inity8
)'-)I ,released 9ll 0a/a-style features 9ll the tools ,command-line and 5DE 5nteropera%ility 8ith 0a/a 0a/aScript Enumerated types First-class methods 9nonymous functions File process collection math io net httpd d%c json test SD6 modules )i!in inheritance Comprehensions 9ssertions )em%er classes refinement Type families Type aliases )odule system 5nterop 8ith 0i7sa8 )a/en 2it-style command-line 0H) and 0S %ac;end
)G ,due in t8o 8ee;s Reified 7enerics Tuples Defaulted Type "arameters Typed functions 8ith defaulted parameters
4 7
8and beyond )J ,Hersion '$+ alpha9nnotations )etamodel 5nterception SKuash the fe8 remainin7 %u7s
Ho* to ind us
Our 8e%site http344ceylon-lan7$or7
Elo7 introduction tour reference spec 9"5 do8nloads .erd3 http344modules$ceylon-lan7$or7
Source repositories
http3447ithu%$com4ceylon
9:A
Muestions# 9ns8ers< http344ceylon-lan7$or7
5 0