Code Generation 2012 - Session Proposal Form

Submission Deadline: Friday December 9th 2011

Session title:

DSLs in Kotlin

Session type and duration:

Tutorial, 60 min

Session abstract:

Kotlin is a statically typed programming language for the JVM, proposed recently by JetBrains. The language is intended for industrial use as a safer and more convenient alternative to Java. The language is fully Java compatible, so one can mix Kotlin and Java sources in the same project. Language documentation is available at http://jetbrains.com/kotlin.

In this session we will demonstrate Kotlin's abilities to define APIs as domain-specific languages (DSLs). This includes explanation of interesting language features illustrated with practical use-cases.

As a flagship example we will present Type-safe Builders, a technique that improves upon Groovy builders (http://groovy.codehaus.org/Builders) by making them statically checked for correctness. This enables specifying declarative data right inside the code. Want to describe a build file? Xml/HTML? Swing UI? Use builders! We will show how Kotlin compiler itself uses builders to specify modules. Along with this example we will show and explain a few other DSLs built in Kotlin.

Benefits of participating:

Participants will learn about Kotlin and how a few language features can be combined to create internal DSLs in a natural and flexible way.

Process & timetable:

Introduction to Kotlin — 7-10 minutes
Q&A - 5 minutes
DSL-enabling features - 15 minutes
Q&A - 5 minutes
Builders (live demo) - 20 minutes
Q&A - 5 minutes

Session outputs:

Slides, example code

Intended Audience:

The session is intended for developers and tech leads.
We expect the audience to be familiar with basic concepts of OOP and some of the statically typed languages (Java, Scala, C#, C++ etc).

Availability:

No constraints

Detailed Description / Supporting Information

Kotlin is a new statically typed JVM-targeted programming language developed by JetBrains and intended for industrial use. Kotlin is designed to be fully Java compatible, and at the same time safer, more concise than Java and way simpler than its main competitor, Scala. Also, IDE support is being developed in parallel with the language itself.

This session focuses on the language features that enable DSL creation and corresponding patterns.

During the introduction, we will give an overview of the language. The features we’re planning to cover include:
* function literals (closures);
* extension functions;
* type inference;
* operator overloading/overriding;
* null safety and automatic casts.

As a flagship example we will present type-safe builders, a technique that improves upon Groovy builders (http://groovy.codehaus.org/Builders) by making them statically checked for correctness. Builders are a flexible and clean way of describing declarative data in the code with very little syntactic overhead. The technique is so handy that Kotlin uses it instead of XML for compiler configuration, which we will show in action along with XML/HTML and Swing UI building.
This part is presented as a live demo within the IntelliJ IDEA IDE for Kotlin. Along with this example we'll demonstrate a DSL for LINQ-like collection processing and how to turn any type into a Fluent interface (http://martinfowler.com/bliki/FluentInterface.html) with extension functions.

This session has not been run before, but the material we use is partly taken from Kotlin talks from OSCON, StrangeLoop and Devoxx.

Main presenter name, contact details and biography

Name: Andrey Breslav
Affiliation: JetBrains
Telephone / Skype: andrey.breslav @ skype
Email: andrey.breslav@jetbrains.com
Biography (up to 100 words):
Andrey is the lead language designer working on Project Kotlin. He joined JetBrains in 2010.