developing android applications with ceylon

Post on 11-Apr-2017

49 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Developing Android applications with

CeylonEnrique Zamudio

@chochosmxgithub.com/chochos

@ceylonlang#CeylonLang

• Programming since 1982• Professionally since 1994

• Java since 2000• FOSS projects:

• j8583• jAlarms• Ceylon

• Java Champion 2015

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

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

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

Union type

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

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

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

Serializing Runnables

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

interface MyTask extends Runnable, Serializable {}

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

class WeirdlyNamedApacheTask implements Runnable, Serializable { ...}

class CumbersomeWrapper implements MyTask { final WeirdlyNamedApacheTask wrappedTask;}

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

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

Intersection type

null

ObjectObject

ObjectObject NullNull

ObjectObject NullNull

AnythingAnything

ObjectObject NullNull

AnythingAnything

StringString NumberNumber

ObjectObject NullNull

AnythingAnything

StringString NumberNumber nullnull

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

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

String | Integer

String | Null

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

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

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

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

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

ObjectObject NullNull

AnythingAnything

StringString NumberNumber nullnull

Algebraic(enumerated) types

abstract class Anything of Object|Null

class Null of null

object null extends Null

class Boolean of true|false

class Comparison of larger|smaller|equal

ObjectObject NullNull

AnythingAnything

StringString NumberNumber nullnull

Bottom type

ObjectObject NullNull

AnythingAnything

NothingNothing

NumberNumberStringString nullnull

Iterable<String,Null>Iterable<String,Nothin

g>

Object & Null

Nothing

Demo time!

Code dive

¿?

try.ceylon-lang.orggithub.com/ceylon

@ceylonlang

enrique@ceylon-lang.org@chochosmx

gitter.im/ceylon

top related