SlideShare a Scribd company logo
1 of 28
Download to read offline
Introducing Ceylon
Twelve Ceylon Idioms
Gavin King - Red Hat
profiles.google.com/gavin.king	
ceylon-lang.org	
!
!
!
We are fans of Java
!
If I appear critical of Java (or any other language) in this presentation it’s because I care
about Java and about programming languages and because understanding what’s wrong
with something is the first step to improving it
!
Powerful,
!
Readable,
!
Predictable.
Verbosity is not the only
relevant measure, but it does
matter
Find more bugs at compile
time, thanks to scrupulous
use of static typing
The developer should be
able to reproduce the
reasoning of the compiler
according to intuitive rules
More powerful tools for
abstraction, so the static
types get in the way less
We spend much more time
reading other people’s code
than we spend writing our
own
Error messages should be
understandable and refer to
concepts inside the user’s
head
!
A Platform,
!
Tooling,
!
Modularity.
Cross platform execution:
JVM or JavaScript VM
A brand new modular SDK
with a minimal language
module
Static typing enables powerful
tools – dynamic languages
simply can’t compete
The job of tools isn’t to fill in
boilerplate, it is to help you
understand and evolve the
code
Ceylon Herd: the community
module repository
A single unifying module
system built into the language,
the tooling, the compiler, the
runtime
“Powerful”
• Languages with static typing are less expressive, in a certain narrow
sense, than dynamic languages
• Ceylon has a very strict type system, fussier even than Java or C#
• So to counterbalance that, we need additional power, within the
type system, to abstract over things, thus regaining expressivity
• Let’s explore the type system via some idioms
Idiom #1
Idiom: functions with multiple outcomes
For example, an operation might return a Person, an Org, or nothing.
!
!
We can handle the different outcomes using instanceof, type casts, and catch:
//Java	
Object findByName(String name) 	
throws NotFoundException { ... }
try {	
Object result = findByName(name);	
if (result instanceof Org) { 	
Org org = (Org) result;	
... 	
}	
if (result instanceof Person) { 	
Person person = (Person) result;	
... 	
}	
}	
catch (NotFoundException nfe) { ... }
Idiom #1
Idiom: functions with multiple outcomes
A function with more than one “outcome” can be defined using a union type.
!
!
We can handle the various outcomes using switch:
Org|Person|NotFound findByName(String name) => ... ;
value result = findByName(name);	
switch (result)	
case (is Org|Person) { ... }	
case (is NotFound) { ... }
Idiom #2
Idiom: functions returning null
Example: retrieving an element from a map. (Special case of multiple outcomes!)
!
!
For a union type of form Null|Item, we have some special syntax sugar.
Item? get(Key key) => ... ;
value map = HashMap { “CET”->cst, “GMT”->gmt, “PST”->pst };	
!
Timezone tz = map[id]; //not well-typed!	
value offset = map[id].rawOffset; //not well-typed!	
!
Timezone? tz = map[id];	
value offset tz = (map[id] else cet).rawOffset;
Item? get(Key key)
Idiom #2
Idiom: functions returning null
What if we know that get() can’t return null, because of some constraint upon the given
key? We can make use of an assertion.
!
!
!
A different way to write this code, removing the need for the assertion:
!
!
!
A similar idiom shows up in iteration of lists.
Item? get(Key key)
if (name in map.keys) { //now we know it’s there	
assert (exists tz = map[name]);	
return ZonedTime(time, tz);	
}
if (exists tz = map[name]) {	
return ZonedTime(time, tz);	
}
Idiom #3
Idiom: iteration over lists
The following is clumsy:
!
!
!
A different way to write this code, removing the need for the assertion:
!
!
We never iterate over list indexes in Ceylon. Not even when iterating subranges:
Item? get(Key key)
for (index in 0:names.size) {	
assert (exists name = names[index]);	
print(index + “:” + name);	
}
for (index->name in names.indexed) {	
print(index + “:” + name);	
}
for (index->name in names[start:length].indexed) {	
print(index+start + “:” + name);	
}
Idiom #4
Idiom: overloading
For example, an operation might apply to an integer, or to a float.
!
!
!
Actually two different, unrelated operations.
!
//Java	
float sqrt(float number) { ... }	
float sqrt(int number) { ... }
Idiom #4
Idiom: overloading
A function parameter can be defined using a union type.
!
!
!
!
Now we have a single operation, and so we can obtain a reference to it:
Float sqrt(Float|Integer number) {	
switch (number)	
case (is Float) { return number^0.5; }	
case (is Integer) { return number.float^0.5; }	
}
Float(Float|Integer) sqrtFun = sqrt;	
!
Float result = sqrtFun(3);
Idiom #4
Idiom: overloading
In some cases, we must use generics.
!
!
!
!
And we can still obtain a reference to it:
!
!
Note that the type argument must be supplied (no “rank 2” polymorphism).
Num sqr<Num>(Num number) 	
given Num of Float|Integer {	
switch (number)	
case (is Float) { ... }	
case (is Integer) { ... }	
}
Float(Float) sqrFun = sqr<Float>;
Idiom #5
Idiom: unions of values
Imagine we want to write down the signature of Set.union() in Java:
!
!
!
This doesn’t actually compile since Java doesn’t have lower bounded type
parameters. (The equivalent thing would work in Scala though.)
//Java	
interface Set<T> {	
public <U super T> Set<U> union(Set<? extends U> set);	
}
Set<Foo> setOfFoo = ... ; 	
Set<Bar> setOfBar = ... ;	
!
Set<Object> setOfFoosAndBars = setOfFoo.union(setOfBar);
Idiom #5
Idiom: unions of values
Unions of values correspond to unions of types!
!
!
!
Exactly the right type pops out automatically.
interface Set<These> {	
shared formal Set<These|Those> union<Those>(Set<Those> set);	
}
Set<Foo> setOfFoo = ... ; 	
Set<Bar> setOfBar = ... ;	
!
Set<Foo|Bar> setOfFoosAndBars = setOfFoo | setOfBar;
Idiom #6
Idiom: intersections of values
Now let’s consider the case of Set.intersection() in Java.
//exercise for the audience	
I tried a bunch of things and didn’t come close to anything like the right thing.
Idiom #6
Idiom: intersections of values
Intersections of values correspond to intersections of types!
!
!
!
Again, exactly the right type pops out automatically.
interface Set<These> {	
shared formal Set<These&Those> intersection<Those>(Set<Those> set);	
}
Set<Foo> setOfFoo = ... ; 	
Set<Bar> setOfBar = ... ;	
!
Set<Foo&Bar> setOfFooBars = setOfFoo & setOfBar;
Idiom #6
Idiom: intersections of values
Example: the coalesce() function eliminates null elements from an Iterable
object.
!
!
Exactly the right type pops out automatically.
!
!
!
(Even though I’m explicitly writing in the types, I could have let them be inferred.)
{Element&Object*} coalesce<Element>({Element*} elements) 	
=> { for (e in elements) if (exists e) e };
{String?*} words = { “hello”, null, “world” };	
{String*} strings = coalesce(words);
Idiom #7
Idiom: empty vs nonempty
Problem: the max() function can return null, but only when the Iterable object
might be empty.
!
!
!
What if we know it’s nonempty? A separate function?
!
!
!
This doesn’t let us abstract.
shared Value? max<Value>({Value*} values) 	
given Value satisfies Comparable<Value> { ... }
shared Value maxNonempty<Value>({Value+} values) 	
given Value satisfies Comparable<Value> { ... }
Idiom #7
Idiom: empty vs nonempty
Solution: the Iterable type has an extra type parameter.
!
!
!
Exactly the right type pops out automatically.
shared Absent|Value max<Value,Absent>(Iterable<Value,Absent> values) 	
given Value satisfies Comparable<Value>	
given Absent satisfies Null { ... }
Null maxOfNone = max {}; //known to be empty	
String maxOfSome = max { “hello”, “world” }; //known to be nonempty	
!
{String*} noneOrSome = ... ;	
String? max = max(noneOrSome); //might be empty or nonempty
Idiom #8
Idiom: multiple return values
For example, an operation might return a Name and an Address.
!
!
!
!
!
We have to define a class.
!
//Java	
class NameAndAddress { ... }	
!
NameAndAddress getNameAndAddress(Person person) {	
return new NameAndAddress(new Name(person.getFirst(), person.getLast()),
person.getHome().getAddress());	
}
Idiom #8
Idiom: multiple return values
A function can be defined to return a tuple type.
!
!
Now a caller can extract the individual return values:
!
!
!
What about other indexes?
[Name,Address] getNameAndAddress(Person person) 	
=> [Name(person.first, person.last), 	
person.home.address];
value nameAndAddress = getNameAndAddress(person);	
Name name = nameAndAddress[0];	
Address address = nameAndAddress[1];
Null missing = nameAndAddress[3];	
Name|Address|Null val = nameAndAddress[index];
Idiom #9
Idiom: spreading tuple return values
Imagine we want to pass the result of getNameAndAddress() to another function or
class initializer.
!
!
We can use the spread operator, *, like in Groovy:
!
!
Or we can work at the function level, using unflatten()
class SnailMail(Name name, Address address) { ... }
value snail = SnailMail(*getNameAndAddress(person));
SnailMail(Person) newSnail 	
= compose(unflatten(SnailMail), getNameAndAddress);	
SnailMail snail = newSnail(person);
Idiom #10
Idiom: abstract over function types
Example: the compose() function composes functions.
!
!
!
But this is not quite as general as it could be!
!
!
What about functions with multiple parameters?
X compose<X,Y,A>(X(Y) x, Y(A) y)(A a)	
=> x(y(a));	
value printSqrt = compose(print,sqrt);	
value printSum = compose(print,plus<Float>);
Idiom #10
Idiom: abstract over function types
Solution: abstract over unknown tuple type.
!
!
!
!
A little uglier, but does the job!
!
!
!
This is actually very useful: write a generic function to memoize another function
Callable<X,Args> compose<X,Y,Args>(X(Y) x, Callable<Y,Args> y) 	
given Args satisfies Anything[]	
=> flatten((Args args) => x(unflatten(y)(args)));
Anything(Float,Float) printSum 	
= compose(print,plus<Float>);
Idiom #11
Idiom: discovery
Example: auto-discover classes annotated test.
!
We use the Ceylon metamodel:
shared test class IdiomTests() { ... }
void metamodel() {	
value declarations = 	
`package org.jboss.example.tests`	
.annotatedMembers<ClassDeclaration,TestAnnotation>();	
for (decl in declarations) {	
if (decl.parameterDeclarations.empty) {	
value model = decl.classApply<Anything,[]>();	
// instantiate the class	
print(model());	
}	
}	
}
Idiom #12
Idiom: tree-structured data
Tree structures occur everywhere: user interfaces, HTML,“configuration”, etc. In the
Java world, we’re forced to use XML for this, losing the advantages of static typing,
tools, etc.
!
In Ceylon, we can use named arguments:
Html html = Html { 	
doctype = html5; 	
Head { title = "Hello"; }; 	
Body {	
for (name in names) {	
P("Hello, ``name``!")	
}	
};	
};

More Related Content

What's hot

JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
From android/java to swift (3)
From android/java to swift (3)From android/java to swift (3)
From android/java to swift (3)allanh0526
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageGiuseppe Arici
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftMichele Titolo
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic courseTran Khoa
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Let's refine your Scala Code
Let's refine your Scala CodeLet's refine your Scala Code
Let's refine your Scala CodeTech Triveni
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic JavascriptBunlong Van
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptNascenia IT
 

What's hot (20)

JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
From android/java to swift (3)
From android/java to swift (3)From android/java to swift (3)
From android/java to swift (3)
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Let's refine your Scala Code
Let's refine your Scala CodeLet's refine your Scala Code
Let's refine your Scala Code
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 

Viewers also liked

Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming Virtual JBoss User Group
 
The Ceylon Type System - Gavin King presentation at QCon Beijing 2011
The Ceylon Type System - Gavin King presentation at QCon Beijing 2011The Ceylon Type System - Gavin King presentation at QCon Beijing 2011
The Ceylon Type System - Gavin King presentation at QCon Beijing 2011devstonez
 
Ceylon - the language and its tools
Ceylon - the language and its toolsCeylon - the language and its tools
Ceylon - the language and its toolsMax Andersen
 
Ceylon SDK by Stéphane Épardaud
Ceylon SDK by Stéphane ÉpardaudCeylon SDK by Stéphane Épardaud
Ceylon SDK by Stéphane ÉpardaudUnFroMage
 
Ceylon.test by Thomáš Hradec
Ceylon.test by Thomáš HradecCeylon.test by Thomáš Hradec
Ceylon.test by Thomáš HradecUnFroMage
 
Ceylon introduction by Stéphane Épardaud
Ceylon introduction by Stéphane ÉpardaudCeylon introduction by Stéphane Épardaud
Ceylon introduction by Stéphane ÉpardaudUnFroMage
 
Ceylon/Java interop by Tako Schotanus
Ceylon/Java interop by Tako SchotanusCeylon/Java interop by Tako Schotanus
Ceylon/Java interop by Tako SchotanusUnFroMage
 
Ceylon.build by Loïc Rouchon
Ceylon.build by Loïc RouchonCeylon.build by Loïc Rouchon
Ceylon.build by Loïc RouchonUnFroMage
 
Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011
Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011
Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011devstonez
 

Viewers also liked (9)

Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming
 
The Ceylon Type System - Gavin King presentation at QCon Beijing 2011
The Ceylon Type System - Gavin King presentation at QCon Beijing 2011The Ceylon Type System - Gavin King presentation at QCon Beijing 2011
The Ceylon Type System - Gavin King presentation at QCon Beijing 2011
 
Ceylon - the language and its tools
Ceylon - the language and its toolsCeylon - the language and its tools
Ceylon - the language and its tools
 
Ceylon SDK by Stéphane Épardaud
Ceylon SDK by Stéphane ÉpardaudCeylon SDK by Stéphane Épardaud
Ceylon SDK by Stéphane Épardaud
 
Ceylon.test by Thomáš Hradec
Ceylon.test by Thomáš HradecCeylon.test by Thomáš Hradec
Ceylon.test by Thomáš Hradec
 
Ceylon introduction by Stéphane Épardaud
Ceylon introduction by Stéphane ÉpardaudCeylon introduction by Stéphane Épardaud
Ceylon introduction by Stéphane Épardaud
 
Ceylon/Java interop by Tako Schotanus
Ceylon/Java interop by Tako SchotanusCeylon/Java interop by Tako Schotanus
Ceylon/Java interop by Tako Schotanus
 
Ceylon.build by Loïc Rouchon
Ceylon.build by Loïc RouchonCeylon.build by Loïc Rouchon
Ceylon.build by Loïc Rouchon
 
Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011
Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011
Introducing the Ceylon Project - Gavin King presentation at QCon Beijing 2011
 

Similar to Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014

Similar to Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014 (20)

2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
JavaScript: The Language
JavaScript: The LanguageJavaScript: The Language
JavaScript: The Language
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Groovy!
Groovy!Groovy!
Groovy!
 

More from hwilming

Introduction Machine Learning - Microsoft
Introduction Machine Learning - MicrosoftIntroduction Machine Learning - Microsoft
Introduction Machine Learning - Microsofthwilming
 
A practical introduction to data science and machine learning
A practical introduction to data science and machine learningA practical introduction to data science and machine learning
A practical introduction to data science and machine learninghwilming
 
Creating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBossCreating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBosshwilming
 
SAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss TechnologiesSAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss Technologieshwilming
 
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7hwilming
 
JBoss EAP clustering
JBoss EAP clustering JBoss EAP clustering
JBoss EAP clustering hwilming
 
JBoss AS / EAP Clustering
JBoss AS / EAP  ClusteringJBoss AS / EAP  Clustering
JBoss AS / EAP Clusteringhwilming
 
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7hwilming
 
JPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEJPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEhwilming
 
Optimierung von JPA-­Anwendungen
Optimierung von JPA-­AnwendungenOptimierung von JPA-­Anwendungen
Optimierung von JPA-­Anwendungenhwilming
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012hwilming
 
Aerogear Java User Group Presentation
Aerogear Java User Group PresentationAerogear Java User Group Presentation
Aerogear Java User Group Presentationhwilming
 
The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012hwilming
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EEhwilming
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EEhwilming
 

More from hwilming (15)

Introduction Machine Learning - Microsoft
Introduction Machine Learning - MicrosoftIntroduction Machine Learning - Microsoft
Introduction Machine Learning - Microsoft
 
A practical introduction to data science and machine learning
A practical introduction to data science and machine learningA practical introduction to data science and machine learning
A practical introduction to data science and machine learning
 
Creating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBossCreating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBoss
 
SAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss TechnologiesSAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss Technologies
 
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
 
JBoss EAP clustering
JBoss EAP clustering JBoss EAP clustering
JBoss EAP clustering
 
JBoss AS / EAP Clustering
JBoss AS / EAP  ClusteringJBoss AS / EAP  Clustering
JBoss AS / EAP Clustering
 
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
 
JPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEJPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SE
 
Optimierung von JPA-­Anwendungen
Optimierung von JPA-­AnwendungenOptimierung von JPA-­Anwendungen
Optimierung von JPA-­Anwendungen
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
 
Aerogear Java User Group Presentation
Aerogear Java User Group PresentationAerogear Java User Group Presentation
Aerogear Java User Group Presentation
 
The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EE
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EE
 

Recently uploaded

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014

  • 1. Introducing Ceylon Twelve Ceylon Idioms Gavin King - Red Hat profiles.google.com/gavin.king ceylon-lang.org !
  • 2. ! ! We are fans of Java
  • 3. ! If I appear critical of Java (or any other language) in this presentation it’s because I care about Java and about programming languages and because understanding what’s wrong with something is the first step to improving it
  • 4. ! Powerful, ! Readable, ! Predictable. Verbosity is not the only relevant measure, but it does matter Find more bugs at compile time, thanks to scrupulous use of static typing The developer should be able to reproduce the reasoning of the compiler according to intuitive rules More powerful tools for abstraction, so the static types get in the way less We spend much more time reading other people’s code than we spend writing our own Error messages should be understandable and refer to concepts inside the user’s head
  • 5. ! A Platform, ! Tooling, ! Modularity. Cross platform execution: JVM or JavaScript VM A brand new modular SDK with a minimal language module Static typing enables powerful tools – dynamic languages simply can’t compete The job of tools isn’t to fill in boilerplate, it is to help you understand and evolve the code Ceylon Herd: the community module repository A single unifying module system built into the language, the tooling, the compiler, the runtime
  • 6. “Powerful” • Languages with static typing are less expressive, in a certain narrow sense, than dynamic languages • Ceylon has a very strict type system, fussier even than Java or C# • So to counterbalance that, we need additional power, within the type system, to abstract over things, thus regaining expressivity • Let’s explore the type system via some idioms
  • 7. Idiom #1 Idiom: functions with multiple outcomes For example, an operation might return a Person, an Org, or nothing. ! ! We can handle the different outcomes using instanceof, type casts, and catch: //Java Object findByName(String name) throws NotFoundException { ... } try { Object result = findByName(name); if (result instanceof Org) { Org org = (Org) result; ... } if (result instanceof Person) { Person person = (Person) result; ... } } catch (NotFoundException nfe) { ... }
  • 8. Idiom #1 Idiom: functions with multiple outcomes A function with more than one “outcome” can be defined using a union type. ! ! We can handle the various outcomes using switch: Org|Person|NotFound findByName(String name) => ... ; value result = findByName(name); switch (result) case (is Org|Person) { ... } case (is NotFound) { ... }
  • 9. Idiom #2 Idiom: functions returning null Example: retrieving an element from a map. (Special case of multiple outcomes!) ! ! For a union type of form Null|Item, we have some special syntax sugar. Item? get(Key key) => ... ; value map = HashMap { “CET”->cst, “GMT”->gmt, “PST”->pst }; ! Timezone tz = map[id]; //not well-typed! value offset = map[id].rawOffset; //not well-typed! ! Timezone? tz = map[id]; value offset tz = (map[id] else cet).rawOffset; Item? get(Key key)
  • 10. Idiom #2 Idiom: functions returning null What if we know that get() can’t return null, because of some constraint upon the given key? We can make use of an assertion. ! ! ! A different way to write this code, removing the need for the assertion: ! ! ! A similar idiom shows up in iteration of lists. Item? get(Key key) if (name in map.keys) { //now we know it’s there assert (exists tz = map[name]); return ZonedTime(time, tz); } if (exists tz = map[name]) { return ZonedTime(time, tz); }
  • 11. Idiom #3 Idiom: iteration over lists The following is clumsy: ! ! ! A different way to write this code, removing the need for the assertion: ! ! We never iterate over list indexes in Ceylon. Not even when iterating subranges: Item? get(Key key) for (index in 0:names.size) { assert (exists name = names[index]); print(index + “:” + name); } for (index->name in names.indexed) { print(index + “:” + name); } for (index->name in names[start:length].indexed) { print(index+start + “:” + name); }
  • 12. Idiom #4 Idiom: overloading For example, an operation might apply to an integer, or to a float. ! ! ! Actually two different, unrelated operations. ! //Java float sqrt(float number) { ... } float sqrt(int number) { ... }
  • 13. Idiom #4 Idiom: overloading A function parameter can be defined using a union type. ! ! ! ! Now we have a single operation, and so we can obtain a reference to it: Float sqrt(Float|Integer number) { switch (number) case (is Float) { return number^0.5; } case (is Integer) { return number.float^0.5; } } Float(Float|Integer) sqrtFun = sqrt; ! Float result = sqrtFun(3);
  • 14. Idiom #4 Idiom: overloading In some cases, we must use generics. ! ! ! ! And we can still obtain a reference to it: ! ! Note that the type argument must be supplied (no “rank 2” polymorphism). Num sqr<Num>(Num number) given Num of Float|Integer { switch (number) case (is Float) { ... } case (is Integer) { ... } } Float(Float) sqrFun = sqr<Float>;
  • 15. Idiom #5 Idiom: unions of values Imagine we want to write down the signature of Set.union() in Java: ! ! ! This doesn’t actually compile since Java doesn’t have lower bounded type parameters. (The equivalent thing would work in Scala though.) //Java interface Set<T> { public <U super T> Set<U> union(Set<? extends U> set); } Set<Foo> setOfFoo = ... ; Set<Bar> setOfBar = ... ; ! Set<Object> setOfFoosAndBars = setOfFoo.union(setOfBar);
  • 16. Idiom #5 Idiom: unions of values Unions of values correspond to unions of types! ! ! ! Exactly the right type pops out automatically. interface Set<These> { shared formal Set<These|Those> union<Those>(Set<Those> set); } Set<Foo> setOfFoo = ... ; Set<Bar> setOfBar = ... ; ! Set<Foo|Bar> setOfFoosAndBars = setOfFoo | setOfBar;
  • 17. Idiom #6 Idiom: intersections of values Now let’s consider the case of Set.intersection() in Java. //exercise for the audience I tried a bunch of things and didn’t come close to anything like the right thing.
  • 18. Idiom #6 Idiom: intersections of values Intersections of values correspond to intersections of types! ! ! ! Again, exactly the right type pops out automatically. interface Set<These> { shared formal Set<These&Those> intersection<Those>(Set<Those> set); } Set<Foo> setOfFoo = ... ; Set<Bar> setOfBar = ... ; ! Set<Foo&Bar> setOfFooBars = setOfFoo & setOfBar;
  • 19. Idiom #6 Idiom: intersections of values Example: the coalesce() function eliminates null elements from an Iterable object. ! ! Exactly the right type pops out automatically. ! ! ! (Even though I’m explicitly writing in the types, I could have let them be inferred.) {Element&Object*} coalesce<Element>({Element*} elements) => { for (e in elements) if (exists e) e }; {String?*} words = { “hello”, null, “world” }; {String*} strings = coalesce(words);
  • 20. Idiom #7 Idiom: empty vs nonempty Problem: the max() function can return null, but only when the Iterable object might be empty. ! ! ! What if we know it’s nonempty? A separate function? ! ! ! This doesn’t let us abstract. shared Value? max<Value>({Value*} values) given Value satisfies Comparable<Value> { ... } shared Value maxNonempty<Value>({Value+} values) given Value satisfies Comparable<Value> { ... }
  • 21. Idiom #7 Idiom: empty vs nonempty Solution: the Iterable type has an extra type parameter. ! ! ! Exactly the right type pops out automatically. shared Absent|Value max<Value,Absent>(Iterable<Value,Absent> values) given Value satisfies Comparable<Value> given Absent satisfies Null { ... } Null maxOfNone = max {}; //known to be empty String maxOfSome = max { “hello”, “world” }; //known to be nonempty ! {String*} noneOrSome = ... ; String? max = max(noneOrSome); //might be empty or nonempty
  • 22. Idiom #8 Idiom: multiple return values For example, an operation might return a Name and an Address. ! ! ! ! ! We have to define a class. ! //Java class NameAndAddress { ... } ! NameAndAddress getNameAndAddress(Person person) { return new NameAndAddress(new Name(person.getFirst(), person.getLast()), person.getHome().getAddress()); }
  • 23. Idiom #8 Idiom: multiple return values A function can be defined to return a tuple type. ! ! Now a caller can extract the individual return values: ! ! ! What about other indexes? [Name,Address] getNameAndAddress(Person person) => [Name(person.first, person.last), person.home.address]; value nameAndAddress = getNameAndAddress(person); Name name = nameAndAddress[0]; Address address = nameAndAddress[1]; Null missing = nameAndAddress[3]; Name|Address|Null val = nameAndAddress[index];
  • 24. Idiom #9 Idiom: spreading tuple return values Imagine we want to pass the result of getNameAndAddress() to another function or class initializer. ! ! We can use the spread operator, *, like in Groovy: ! ! Or we can work at the function level, using unflatten() class SnailMail(Name name, Address address) { ... } value snail = SnailMail(*getNameAndAddress(person)); SnailMail(Person) newSnail = compose(unflatten(SnailMail), getNameAndAddress); SnailMail snail = newSnail(person);
  • 25. Idiom #10 Idiom: abstract over function types Example: the compose() function composes functions. ! ! ! But this is not quite as general as it could be! ! ! What about functions with multiple parameters? X compose<X,Y,A>(X(Y) x, Y(A) y)(A a) => x(y(a)); value printSqrt = compose(print,sqrt); value printSum = compose(print,plus<Float>);
  • 26. Idiom #10 Idiom: abstract over function types Solution: abstract over unknown tuple type. ! ! ! ! A little uglier, but does the job! ! ! ! This is actually very useful: write a generic function to memoize another function Callable<X,Args> compose<X,Y,Args>(X(Y) x, Callable<Y,Args> y) given Args satisfies Anything[] => flatten((Args args) => x(unflatten(y)(args))); Anything(Float,Float) printSum = compose(print,plus<Float>);
  • 27. Idiom #11 Idiom: discovery Example: auto-discover classes annotated test. ! We use the Ceylon metamodel: shared test class IdiomTests() { ... } void metamodel() { value declarations = `package org.jboss.example.tests` .annotatedMembers<ClassDeclaration,TestAnnotation>(); for (decl in declarations) { if (decl.parameterDeclarations.empty) { value model = decl.classApply<Anything,[]>(); // instantiate the class print(model()); } } }
  • 28. Idiom #12 Idiom: tree-structured data Tree structures occur everywhere: user interfaces, HTML,“configuration”, etc. In the Java world, we’re forced to use XML for this, losing the advantages of static typing, tools, etc. ! In Ceylon, we can use named arguments: Html html = Html { doctype = html5; Head { title = "Hello"; }; Body { for (name in names) { P("Hello, ``name``!") } }; };