Developing Android
applications with
Ceylon
Enrique Zamudio
@chochosmx
github.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);
String password);
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 {}
Serializable {}
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
ObjectObjectObjectObject
ObjectObjectObjectObject NullNullNullNull
ObjectObjectObjectObject NullNullNullNull
AnythingAnythingAnythingAnything
ObjectObjectObjectObject NullNullNullNull
AnythingAnythingAnythingAnything
StringStringStringString NumberNumberNumberNumber
ObjectObjectObjectObject NullNullNullNull
AnythingAnythingAnythingAnything
StringStringStringString NumberNumberNumberNumber nullnullnullnull
String s = null;
Integer s = null;
Null n = null;
Null n = null;
Null n = null;
String s = null;
Integer s = null;
Null n = null;
Null n = null;
Null n = null;
✘
String | Integer
String | Null
String | Null
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 COMPILE
if (exists s) {
...
}
}
}
}
}
ObjectObjectObjectObject NullNullNullNull
AnythingAnythingAnythingAnything
StringStringStringString NumberNumberNumberNumber nullnullnullnull
Algebraic
(enumerated) types
(enumerated) types
of Object|Null
class Null of null
object null extends Null
Null
Null
Null
Null
class Boolean
of true|false
class Comparison
of larger|smaller|equal
larger|smaller|equal
larger|smaller|equal
larger|smaller|equal
larger|smaller|equal
ObjectObjectObjectObject NullNullNullNull
AnythingAnythingAnythingAnything
StringStringStringString NumberNumberNumberNumber nullnullnullnull
Bottom type
ObjectObjectObjectObject NullNullNullNull
AnythingAnythingAnythingAnything
NothingNothingNothingNothing
NumberNumberNumberNumberStringStringStringString nullnullnullnull
Iterable<String,Nothing>
Object & Null
Nothing
Nothing
Nothing
Nothing
Nothing
Nothing
Demo time!
Code dive
¿?
try.ceylon-lang.org
github.com/ceylon
@ceylonlang
enrique@ceylon-lang.org
@chochosmx
gitter.im/ceylon

Developing Android applications with Ceylon