soirée ceylon avec stéphane epardaud
Post on 24-May-2015
272 Views
Preview:
DESCRIPTION
TRANSCRIPT
1
Introduction à CeylonStéphane Épardaud
Red Hat
2
Plan d´attaque
• Ceylon, c'est quoi?
• Pourquoi
• Petit tour
• Démo
• La communauté
• Statut
2
3
À propos de Stéphane Épardaud
• Projets Open-Source–RESTEasy, Ceylon
–jax-doclets, modules Play!, Stamps.js
• Contributeur Ceylon depuis…–13 mai 2011 (un mois après Ceylon sur SlashDot)
–compilo, ceylondoc, Herd
• Équipe Riviera JUG
• http://stephane.epardaud.fr
3
4
Origines de Ceylon
• Lancé et dirigé par Gavin King
• Résoudre les frustrations de Java
4
5
Qu´est-ce que Ceylon !
• Ceylon est–puissant, lisible, prédictible
• Ceylon a
–une plate-forme, modularité, outillage
5
6
Introduction à Ceylon
7
Une bête classe
• Ça vous rappelle quelque-chose ?
7
class Rectangle() { Integer width = 0; Integer height = 0; Integer area() { return width * height; }}
8
Une vraie classe Ceylon
• Pas (trop) de surprise
8
shared class Rectangle(width, height) {
shared Integer width; shared Integer height; shared Integer area() { return width * height; }}
9
Où est mon constructeur ?
• Dans le corps de la classe
9
shared class Rectangle(width, height) { shared Integer width; shared Integer height;
// it is here! if (width == 0 || height == 0) {
throw; } shared Integer area() { return width * height; }}
10
Premières différences
• Règles d´accès plus simple–Pas de `protected`, `package`, `private`
–`shared` = quasi-public, sinon scope-privé
10
11
Attributs
• Immuable par défaut
11
class CircleFromMarseille() { Integer scale = 1; variable Integer radius := 2; radius++; Integer diameter { return diameter * 2; } assign diameter { radius := diameter / 2; }}
12
Attributs
• Sauf si marqué variable
• Affecté avec :=
12
class CircleFromMarseille() { Integer scale = 1; variable Integer radius := 2; radius++; Integer diameter { return radius * 2; } assign diameter { radius := diameter / 2; }}
13
Attributs
• Getter/setter sans le syndrôme du canal carpien
13
class CircleFromMarseille() { Integer scale = 1; variable Integer radius := 2; radius++; Integer diameter { return radius * 2; } assign diameter { radius := diameter / 2; }}
14
Héritage
14
shared class Point(x, y) { shared Integer x; shared Integer y;}
shared class Point3D(x, y, z) extends Point(x, y) { shared Integer z;}
15
Abstractions
• Méthodes, attributs et classes peuvent être redéfinies–factory pattern
• On ne peut pas redéfinir sauf si–`default`: peut être redéfini, avec impl par défaut
–`formal`: doit être redéfini, sans impl par défaut
• `@Override` en Java => `actual` en Ceylon–Pas optionnel
15
16
Abstractions (exemple)
16
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";}
17
Surcharge
• Pas de surcharge–WTF!?*
• La surcharge, c´est mal
* : Heing !?
17
18
La surcharge, ça sert pour
• Les paramètres optionnels–Ceylon les supporte–Même le passage par nom
• Pour travailler sur des (sous-)types différents–Pas solide si un nouveau sous-type est introduit
–Ceylon supporte les types unions et les switch par type
18
19
Paramètres optionnels Passage par nom
19
class Rectangle(Integer width = 2, Integer height = width * 2) { shared Integer area() { return width * height; }}void makeRectangle() { Rectangle rectangle = Rectangle(); Rectangle biggerRectangle = Rectangle { height = 4; width = 3; };}
20
Switch par type
20
void workWithRectangle(Rectangle rect) {}void workWithCircle(Circle circle) {}void workWithShape(Shape shape) {}
shared void supportsSubTyping(Shape fig) { switch(fig) case(is Rectangle) { workWithRectangle(fig); } case(is Circle) { workWithCircle(fig); } else { workWithShape(fig); }}
21
Non aux répétitions
21
interface Figure3D { shared formal Float area; shared formal Float depth; shared formal Float volume;}
class Cube(Float width) satisfies Figure3D { shared actual Float area = width * width; shared actual Float depth = width; shared actual Float volume = area * depth;}
class Cylinder(Integer radius, depth) satisfies Figure3D { shared actual Float area = 3.14 * radius ** 2; shared actual Float depth; shared actual Float volume = area * depth;}
22
Interfaces avec implémentations
22
interface Figure3D { shared formal Float area; shared formal Float depth; shared Float volume { return area * depth; }}
class Cube(Float width) satisfies Figure3D { shared actual Float area = width * width; shared actual Float depth = width;}
class Cylinder(Integer radius, depth) satisfies Figure3D { shared actual Float area = 3.14 * radius ** 2; shared actual Float depth;}
23
Héritage multiple?! Arg…
23
• Pas d´état (initialisation)–Pas de problème de précédence–Une seule superclasse
• Redéfinir méthode en cas d'ambigüité
24
Ceylon est très régulier
Integer attribute = 1;Integer attribute2 { return 2; }void method() {}interface Interface {}
class Class(Integer x){ Integer attribute = x; Integer attribute2 { return x; } class InnerClass() {} interface InnerInterface {} void method(Integer y){ Integer attribute; Integer attribute2 { return y; } class LocalClass() {} interface LocalInterface {} void innerMethod() {} }}
25
Structure hiérarchique
25
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; } }};
26
Preuve mathématique formelle du système de type et d´effet
27
Sémantique 1/154
27
28
STOP!Hammer Time…
29
Types typiques
29
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);
30
À mort les NPEs
30
31
Typez en sécurité
31
// 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"); }
32
Un peu de sucre ?
32
// default value Cube cube2 = cubeOrNoCube() ? Cube(3.0); // nullsafe access Float? area = cube?.area; // nullsafe array access Cube[]? maybeList = cubeList(); Cube? c = maybeList?[2];
33
Operations sur les listes
33
Integer[] numbers = {1,2,3};// slicesInteger[] subList = numbers[1..2];Integer[] rest = numbers[1...];// map/spreadInteger[] successors = numbers[].successor;
34
(un peu de) Typage
35
Type union
• Pour stoquer une valeur parmi une liste de types
• `TypeA|TypeB`
• On doit vérifier le vrai type avant de s´en servir
• `Type?` est un alias pour `Type|Nothing`
35
36
Exemple de type union
36
class Apple() { shared void eat() {}}
class Garbage() { shared void throwAway() {}}
void unions() { Sequence<Apple|Garbage> boxes = { Apple(), Garbage() }; for (Apple|Garbage box in boxes) { print(box.string); if (is Apple box) { apple.eat(); } else if (is Garbage box) { box.throwAway(); } }}
37
Type intersection
37
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();}
38
Beaucoup d´autres fonctionalités
• Paramètres de types
• Singletons et classes anonymes
• Introductions
• Références d´attribut et de méthode
38
• Clôtures
• Application partielle
• Annotations
• Alias de types
• Meta-modèle
• Interception
39
Modularité
• Intégré au langage
• Et dans les outils39
40
Herd
● Notre dépôt de modules « nouvelle génération »
● Sur http://modules.ceylon-lang.org− Déjà dispo, et utilisable par les
outils● Interface intuitive et jolie à la Github
− Collaboratif● Logiciel Libre
− Dépôts privés encouragés
41
Des mots…et démo !
Avec de vrais morceaux d´IDE
* Peut contenir des traces de Herd
42
Communauté
● Complètement ouverte● Des gens de JBoss/RedHat● Et de (très) actifs contributeurs
− Gary, Andrew, David (Serli), Ross, Tomáš, Sergej, Flavio…
● Et vous !
42
43
Un projet sympa
• Des gens sympas :)• Les meilleurs outils–github, ant, Eclipse, HTML5, Awestruct, Java, JavaScript, OpenShift, Play!
• De nombreux sous-projets–spec, typechecker, Java compiler, JavaScript compiler, Eclipse IDE, Web IDE, Herd, module system, ceylondoc, Ant/Maven plugins
43
44
Vers l´infini…
• Cinq étapes pour atteindre 1.0
• Quelques fonctionalités attendront 1.1
• M1 (finie)–Au minimum toutes les fonctionalités de Java
–Tous les outils (y-compris l´IDE)
• M2 (finie)–Interoperabilité avec Java
–Types énumérés
–Méthodes d´ordre supérieur44
45
…et au delà !
• M3–Fonctions
anonymes
–Modules IO, math–Héritage mixin
• M4–Classes
imbriquées–Alias de types
45
• M5 (Ceylon 1.0)–Annotations
–Génériques réifiés
–Metamodèle–Interception
46
Où nous trouver?
• Notre site : http://ceylon-lang.org–Blog, introduction, tour, référence, spec, API,
téléchargements–Herd : http://modules.ceylon-lang.org
• Dépôt [sic] de source–http://github.com/ceylon
• Listes de développeurs, utilisateurs–Google groups : ceylon-dev, ceylon-users
• Google+ : http://ceylon-lang.org/+• Twitter : @ceylonlang
46
47
Q&R
• Questions ! Réponses ?
• http://ceylon-lang.org
47
top related