developing android applications with ceylon

40
Developing Android applications with Ceylon Enrique Zamudio @chochosmx github.com/chochos @ceylonlang #CeylonLang

Upload: enrique-zamudio-lopez

Post on 11-Apr-2017

49 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Developing Android applications with Ceylon

Developing Android applications with

CeylonEnrique Zamudio

@chochosmxgithub.com/chochos

@ceylonlang#CeylonLang

Page 2: Developing Android applications with Ceylon

• Programming since 1982• Professionally since 1994

• Java since 2000• FOSS projects:

• j8583• jAlarms• Ceylon

• Java Champion 2015

Page 3: Developing Android applications with Ceylon

Why Ceylon?• Many Android devs are not too keen on

Java

• Some don't even consider it to be a "real" Java

• Type system is somewhat limited

• Lots of anonymous classes throughout codebase

Page 4: Developing Android applications with Ceylon

Ceylon advantages• Functions are first-class citizens

• Higher-order functions

• Union and intersection types

• Easier to manage generics

• No checked exceptions

• More typesafe (typesafer?) than Java

• Typesafe null, bounded generics

Page 5: Developing Android applications with Ceylon

User|LoginError login( String username, String password);

Union type

Page 6: Developing Android applications with Ceylon

if (is User r = login(u,p)) { //it's a user print(r.username);} else { //it's an error print(r.reason);}

Page 7: Developing Android applications with Ceylon

Object obj = ...;if (obj instanceof Foo) { print(((Foo)obj).foo);}

Page 8: Developing Android applications with Ceylon

Object obj = ...;if (obj instanceof Foo) { print(((Bar)obj).bar);}

Page 9: Developing Android applications with Ceylon

Serializing Runnables

Page 10: Developing Android applications with Ceylon

void send(??? task) { //send task over the wire //is run on the other side}

Page 11: Developing Android applications with Ceylon

interface MyTask extends Runnable, Serializable {}

Page 12: Developing Android applications with Ceylon

void send(MyTask task) { //send task over the wire //is run on the other side}

Page 13: Developing Android applications with Ceylon

class WeirdlyNamedApacheTask implements Runnable, Serializable { ...}

Page 14: Developing Android applications with Ceylon

class CumbersomeWrapper implements MyTask { final WeirdlyNamedApacheTask wrappedTask;}

Page 15: Developing Android applications with Ceylon

void send( Runnable & Serializable task) { //send task over the wire //is run on the other side}

Page 16: Developing Android applications with Ceylon

void send( Runnable & Serializable task) { //send task over the wire //is run on the other side}

Intersection type

Page 17: Developing Android applications with Ceylon

null

Page 18: Developing Android applications with Ceylon

ObjectObject

Page 19: Developing Android applications with Ceylon

ObjectObject NullNull

Page 20: Developing Android applications with Ceylon

ObjectObject NullNull

AnythingAnything

Page 21: Developing Android applications with Ceylon

ObjectObject NullNull

AnythingAnything

StringString NumberNumber

Page 22: Developing Android applications with Ceylon

ObjectObject NullNull

AnythingAnything

StringString NumberNumber nullnull

Page 23: Developing Android applications with Ceylon

String s = null;Integer s = null;Null n = null;

Page 24: Developing Android applications with Ceylon

String s = null;Integer s = null;Null n = null;✘

Page 25: Developing Android applications with Ceylon

String | Integer

String | Null

Page 26: Developing Android applications with Ceylon

String|Integer a = 1;String|Integer b = "one";

String|Null s1 = "s";String|Null s2 = null;

Page 27: Developing Android applications with Ceylon

String|Integer a = 1;String|Integer b = "one";

String? s1 = "s";String? s2 = null;

Page 28: Developing Android applications with Ceylon

String? s = foo();print(s.size); //WON'T COMPILEif (exists s) { ...}

Page 29: Developing Android applications with Ceylon

ObjectObject NullNull

AnythingAnything

StringString NumberNumber nullnull

Page 30: Developing Android applications with Ceylon

Algebraic(enumerated) types

Page 31: Developing Android applications with Ceylon

abstract class Anything of Object|Null

class Null of null

object null extends Null

Page 32: Developing Android applications with Ceylon

class Boolean of true|false

class Comparison of larger|smaller|equal

Page 33: Developing Android applications with Ceylon

ObjectObject NullNull

AnythingAnything

StringString NumberNumber nullnull

Page 34: Developing Android applications with Ceylon

Bottom type

Page 35: Developing Android applications with Ceylon

ObjectObject NullNull

AnythingAnything

NothingNothing

NumberNumberStringString nullnull

Page 36: Developing Android applications with Ceylon

Iterable<String,Null>Iterable<String,Nothin

g>

Object & Null

Nothing

Page 37: Developing Android applications with Ceylon

Demo time!

Page 38: Developing Android applications with Ceylon

Code dive

Page 39: Developing Android applications with Ceylon

¿?

Page 40: Developing Android applications with Ceylon

try.ceylon-lang.orggithub.com/ceylon

@ceylonlang

[email protected]@chochosmx

gitter.im/ceylon