Kotlin in the CommunityTeam
Productivity Tools
Languages
Kotlin
MPS
TeamCity
YouTrack
Upsource
IDEs
IntelliJ IDEA
PhpStorm
PyCharm
RubyMine
WebStorm
AppCode
CLion
.NET & Visual Studio
developer productivity tools
ReSharper
ReSharper С++
dotCover
dotTrace
dotMemory
dotPeek
Kotlin: 

Why Do You Care?
Dmitry Jemerov <yole@jetbrains.com>
2
3
• Statically typed programming language targeting
the JVM
• Support for functional and OO paradigms
• Pragmatic, safe, concise, great Java interop
• Free and open-source
• In public beta, 1.0 coming Real Soon Now
4
Outline
• Why Kotlin was created
• Kotlin feature highlights
• How and why we’re using Kotlin
• Where Kotlin works best
• How you can benefit from Kotlin in your projects
5
Why was Kotlin
created?
6
“We’ve built tools to support
so many nice languages,
and we’re still using Java”
7
JetBrains, 2010
Developer Productivity
8
Develop with Pleasure
9
Thought Leadership
• Programming languages are a popular discussion
topic
• IntelliJ IDEA is always going to have best support
for Kotlin
10
Good chance of success
• Technical: experience building intelligent tools to
support other languages
• Marketing: company reputation and user trust
11
Kotlin Feature
Highlights
12
Primary Constructor
class Person(val firstName: String,

val lastName: String) {



}

Properties
class Person(val firstName: String,

val lastName: String) {



val fullName: String

get() = "$firstName $lastName"

}

Properties
class Person(val firstName: String,

val lastName: String) {



val fullName: String

get() = "$firstName $lastName"

}

Smart Casts
interface Expr



class Constant(val value: Double) : Expr



class Sum(val op1: Expr, val op2: Expr)

: Expr

Smart Casts
fun eval(e: Expr): Double = when(e) {

}
Smart Casts
fun eval(e: Expr): Double = when(e) {

}
Smart Casts
fun eval(e: Expr): Double = when(e) {

is Constant -> e.value

}
Smart Casts
fun eval(e: Expr): Double = when(e) {

is Constant -> e.value

}
class Constant(val value: Double) : Expr
Smart Casts
fun eval(e: Expr): Double = when(e) {

is Constant -> e.value

is Sum -> eval(e.op1) + eval(e.op2)

else ->
throw IllegalArgumentException()

}
class Sum(val op1: Expr, val op2: Expr)

: Expr
Extension Functions
fun String.lastChar() = 

this.get(this.length - 1)


"abc".lastChar()
Extension Functions
fun String.lastChar() = 

this.get(this.length - 1)


"abc".lastChar()
Extension Functions
fun String.lastChar() = 

this.get(this.length - 1)


"abc".lastChar()
Nullability
Nullability
class TreeNode(val parent: TreeNode?,

val left: TreeNode?,

val right: TreeNode?) {



}
Nullability
class TreeNode(val parent: TreeNode?,

val left: TreeNode?,

val right: TreeNode?) {



fun depth(): Int {

val parentDepth = if (parent != null) 

parent.depth()

else

0

return parentDepth + 1

}

}
Nullability
class TreeNode(val parent: TreeNode?,

val left: TreeNode?,

val right: TreeNode?) {



fun depth(): Int {

return (parent?.depth() ?: 0) + 1

}

}

Nullability
class TreeNode(val parent: TreeNode?,

val left: TreeNode?,

val right: TreeNode?) {



fun depth(): Int {

return (parent?.depth() ?: 0) + 1

}

}

Collections and Lambdas
fun nobleNames(persons: List<Person>)

= persons

.filter { "von " in it.lastName }

Collections and Lambdas
fun nobleNames(persons: List<Person>)

= persons

.filter { "von " in it.lastName }

Collections and Lambdas
fun nobleNames(persons: List<Person>)

= persons

.filter { "von " in it.lastName }

.sortBy { it.firstName }

Collections and Lambdas
fun nobleNames(persons: List<Person>)

= persons

.filter { "von " in it.lastName }

.sortBy { it.firstName }

.map { "${it.firstName} ${it.lastName}” }
How JetBrains Uses
Kotlin
34
Projects Using Kotlin
• Kotlin
• JetProfile (CRM, sales and license management)
• IntelliJ IDEA 15
• YouTrack v.next
• 2 new unannounced projects
• Research projects related to bioinformatics
• Plugins, Intranet services etc.
35
JetProfile
36
Проект JetProfile
37
JetProfile Project
• Started in July 2013
• Replaces old Spring-based system
• 100% Kotlin, 100k LOC
• Team of 6 developers
38
IntelliJ IDEA
39
Kotlin in IntelliJ IDEA
• In tests since version 14, in production since 15
• 74k LOC in Kotlin, out of which 18k in tests
• A few developers actively using Kotlin
• Kotlin team provides support with updating to new
Kotlin versions
40
Where Kotlin Works
Best
The Strengths of Kotlin
• Modeling the data of your application concisely
and expressively
• Creating reusable abstractions using functional
programming techniques
• Creating expressive domain-specific languages
Kotlin on the Server Side
• Java interop ensures that all existing Java
frameworks can be used
• No rewrite required to start using Kotlin in existing
codebase
• Existing investment is fully preserved
Server-side Kotlin
Frameworks
• Kara: Web framework powering JetProfile

https://github.com/shafirov/kara
• Exposed: Database access framework

https://github.com/JetBrains/exposed
• Ktor: Experimental next generation Web framework

https://github.com/kotlin/ktor
Kara: HTML Builders
fun HtmlBodyTag.renderPersonList(
persons: Collection<Person>)
{

table {

for (person in persons) {

tr {

td { +person.name }

td { +person.age }

}

}

}

}
45
Kara: HTML Builders
fun HtmlBodyTag.renderPersonList(
persons: Collection<Person>)
{

table {

for (person in persons) {

tr {

td { +person.name }

td { +person.age }

}

}

}

}
46
Exposed: Table structure
object CountryTable : IdTable() {

val name = varchar("name", 250)
.uniqueIndex()
val iso = varchar("iso", 3)
.uniqueIndex()


val currency = varchar("currency", 3)

}
47
Exposed: Entities
class Country(id: EntityID) : Entity(id) {

var name: String by CountryTable.name

val allCustomers by Customer.referrersOn(
CustomerTable.country_id)

}
48
Exposed: Queries
val germany = Country
.find { CountryTable.iso eq "de" }
.first()
49
Kotlin for Android
• Compatible with Java 6
• Small runtime library
• Great tooling in Android Studio
• Compatible with existing Java libraries and tools
• 100% Java performance
Kotlin Tools for Android
• Kotlin Android Extensions: no more findViewById()
• Anko: DSL for UI, extension functions

https://github.com/jetbrains/anko
• KApt: annotation processing
Kotlin Android Extensions
import kotlinx.android.synthetic.activity_main.click_me_button



public class MainActivity : Activity() {



override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)



click_me_button.onClick {

toast("Thank you!")

}

}
}
Kotlin Android Extensions
import kotlinx.android.synthetic.activity_main.click_me_button



public class MainActivity : Activity() {



override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)



click_me_button.onClick {

toast("Thank you!")

}

}
}
Kotlin Android Extensions
import kotlinx.android.synthetic.activity_main.click_me_button



public class MainActivity : Activity() {



override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)



click_me_button.onClick {

toast("Thank you!")

}

}
}
Anko: Android UI Builders
tableLayout {

for (location in locations) {

tableRow {

textView(text = location.name)

.lparams(column = 1)

}

}

}
Kotlin in the Community
How to succeed 

with Kotlin
57
Take initiative
58
Take initiative
• Kotlin is not a silver bullet and not a magical
solution for the problems of your project
• Kotlin makes you more productive and your work
more enjoyable
• Try it and share the results with your teammates
59
Don’t wait for a new project
• Kotlin can be easily integrated into existing Java
codebases
60
Where to start using Kotlin
• Tests - OK not informative
• Plugins and utilities - better
• Core and frameworks - best
61
Don’t fear the learning curve
• At JetBrains, summer interns become productive
with Kotlin very quickly and deliver great results
62
Use the Java to Kotlin
converter
• Convert only the classes that you’re going to
modify
• Cleanup and refactor the code produced by the
converter
63
Use the Java to Kotlin
converter
64
Summary
• JetBrains entrusts the most business-critical tasks
to Kotlin
• Kotlin works great for both server-side and Android
development
• Take initiative and start using Kotlin today!
65
Q&A
https://kotlinlang.org/
https://try.kotlinlang.org/
@kotlin
yole@jetbrains.com
@intelliyole
67

Kotlin: Why Do You Care?

  • 1.
    Kotlin in theCommunityTeam Productivity Tools Languages Kotlin MPS TeamCity YouTrack Upsource IDEs IntelliJ IDEA PhpStorm PyCharm RubyMine WebStorm AppCode CLion .NET & Visual Studio developer productivity tools ReSharper ReSharper С++ dotCover dotTrace dotMemory dotPeek
  • 2.
    Kotlin: 
 Why DoYou Care? Dmitry Jemerov <yole@jetbrains.com> 2
  • 3.
  • 4.
    • Statically typedprogramming language targeting the JVM • Support for functional and OO paradigms • Pragmatic, safe, concise, great Java interop • Free and open-source • In public beta, 1.0 coming Real Soon Now 4
  • 5.
    Outline • Why Kotlinwas created • Kotlin feature highlights • How and why we’re using Kotlin • Where Kotlin works best • How you can benefit from Kotlin in your projects 5
  • 6.
  • 7.
    “We’ve built toolsto support so many nice languages, and we’re still using Java” 7 JetBrains, 2010
  • 8.
  • 9.
  • 10.
    Thought Leadership • Programminglanguages are a popular discussion topic • IntelliJ IDEA is always going to have best support for Kotlin 10
  • 11.
    Good chance ofsuccess • Technical: experience building intelligent tools to support other languages • Marketing: company reputation and user trust 11
  • 12.
  • 13.
    Primary Constructor class Person(valfirstName: String,
 val lastName: String) {
 
 }

  • 14.
    Properties class Person(val firstName:String,
 val lastName: String) {
 
 val fullName: String
 get() = "$firstName $lastName"
 }

  • 15.
    Properties class Person(val firstName:String,
 val lastName: String) {
 
 val fullName: String
 get() = "$firstName $lastName"
 }

  • 16.
    Smart Casts interface Expr
 
 classConstant(val value: Double) : Expr
 
 class Sum(val op1: Expr, val op2: Expr)
 : Expr

  • 17.
    Smart Casts fun eval(e:Expr): Double = when(e) {
 }
  • 18.
    Smart Casts fun eval(e:Expr): Double = when(e) {
 }
  • 19.
    Smart Casts fun eval(e:Expr): Double = when(e) {
 is Constant -> e.value
 }
  • 20.
    Smart Casts fun eval(e:Expr): Double = when(e) {
 is Constant -> e.value
 } class Constant(val value: Double) : Expr
  • 21.
    Smart Casts fun eval(e:Expr): Double = when(e) {
 is Constant -> e.value
 is Sum -> eval(e.op1) + eval(e.op2)
 else -> throw IllegalArgumentException()
 } class Sum(val op1: Expr, val op2: Expr)
 : Expr
  • 22.
    Extension Functions fun String.lastChar()= 
 this.get(this.length - 1) 
 "abc".lastChar()
  • 23.
    Extension Functions fun String.lastChar()= 
 this.get(this.length - 1) 
 "abc".lastChar()
  • 24.
    Extension Functions fun String.lastChar()= 
 this.get(this.length - 1) 
 "abc".lastChar()
  • 25.
  • 26.
    Nullability class TreeNode(val parent:TreeNode?,
 val left: TreeNode?,
 val right: TreeNode?) {
 
 }
  • 27.
    Nullability class TreeNode(val parent:TreeNode?,
 val left: TreeNode?,
 val right: TreeNode?) {
 
 fun depth(): Int {
 val parentDepth = if (parent != null) 
 parent.depth()
 else
 0
 return parentDepth + 1
 }
 }
  • 28.
    Nullability class TreeNode(val parent:TreeNode?,
 val left: TreeNode?,
 val right: TreeNode?) {
 
 fun depth(): Int {
 return (parent?.depth() ?: 0) + 1
 }
 }

  • 29.
    Nullability class TreeNode(val parent:TreeNode?,
 val left: TreeNode?,
 val right: TreeNode?) {
 
 fun depth(): Int {
 return (parent?.depth() ?: 0) + 1
 }
 }

  • 30.
    Collections and Lambdas funnobleNames(persons: List<Person>)
 = persons
 .filter { "von " in it.lastName }

  • 31.
    Collections and Lambdas funnobleNames(persons: List<Person>)
 = persons
 .filter { "von " in it.lastName }

  • 32.
    Collections and Lambdas funnobleNames(persons: List<Person>)
 = persons
 .filter { "von " in it.lastName }
 .sortBy { it.firstName }

  • 33.
    Collections and Lambdas funnobleNames(persons: List<Person>)
 = persons
 .filter { "von " in it.lastName }
 .sortBy { it.firstName }
 .map { "${it.firstName} ${it.lastName}” }
  • 34.
  • 35.
    Projects Using Kotlin •Kotlin • JetProfile (CRM, sales and license management) • IntelliJ IDEA 15 • YouTrack v.next • 2 new unannounced projects • Research projects related to bioinformatics • Plugins, Intranet services etc. 35
  • 36.
  • 37.
  • 38.
    JetProfile Project • Startedin July 2013 • Replaces old Spring-based system • 100% Kotlin, 100k LOC • Team of 6 developers 38
  • 39.
  • 40.
    Kotlin in IntelliJIDEA • In tests since version 14, in production since 15 • 74k LOC in Kotlin, out of which 18k in tests • A few developers actively using Kotlin • Kotlin team provides support with updating to new Kotlin versions 40
  • 41.
  • 42.
    The Strengths ofKotlin • Modeling the data of your application concisely and expressively • Creating reusable abstractions using functional programming techniques • Creating expressive domain-specific languages
  • 43.
    Kotlin on theServer Side • Java interop ensures that all existing Java frameworks can be used • No rewrite required to start using Kotlin in existing codebase • Existing investment is fully preserved
  • 44.
    Server-side Kotlin Frameworks • Kara:Web framework powering JetProfile
 https://github.com/shafirov/kara • Exposed: Database access framework
 https://github.com/JetBrains/exposed • Ktor: Experimental next generation Web framework
 https://github.com/kotlin/ktor
  • 45.
    Kara: HTML Builders funHtmlBodyTag.renderPersonList( persons: Collection<Person>) {
 table {
 for (person in persons) {
 tr {
 td { +person.name }
 td { +person.age }
 }
 }
 }
 } 45
  • 46.
    Kara: HTML Builders funHtmlBodyTag.renderPersonList( persons: Collection<Person>) {
 table {
 for (person in persons) {
 tr {
 td { +person.name }
 td { +person.age }
 }
 }
 }
 } 46
  • 47.
    Exposed: Table structure objectCountryTable : IdTable() {
 val name = varchar("name", 250) .uniqueIndex() val iso = varchar("iso", 3) .uniqueIndex() 
 val currency = varchar("currency", 3)
 } 47
  • 48.
    Exposed: Entities class Country(id:EntityID) : Entity(id) {
 var name: String by CountryTable.name
 val allCustomers by Customer.referrersOn( CustomerTable.country_id)
 } 48
  • 49.
    Exposed: Queries val germany= Country .find { CountryTable.iso eq "de" } .first() 49
  • 50.
    Kotlin for Android •Compatible with Java 6 • Small runtime library • Great tooling in Android Studio • Compatible with existing Java libraries and tools • 100% Java performance
  • 51.
    Kotlin Tools forAndroid • Kotlin Android Extensions: no more findViewById() • Anko: DSL for UI, extension functions
 https://github.com/jetbrains/anko • KApt: annotation processing
  • 52.
    Kotlin Android Extensions importkotlinx.android.synthetic.activity_main.click_me_button
 
 public class MainActivity : Activity() {
 
 override fun onCreate(savedInstanceState: Bundle?) {
 super.onCreate(savedInstanceState)
 setContentView(R.layout.activity_main)
 
 click_me_button.onClick {
 toast("Thank you!")
 }
 } }
  • 53.
    Kotlin Android Extensions importkotlinx.android.synthetic.activity_main.click_me_button
 
 public class MainActivity : Activity() {
 
 override fun onCreate(savedInstanceState: Bundle?) {
 super.onCreate(savedInstanceState)
 setContentView(R.layout.activity_main)
 
 click_me_button.onClick {
 toast("Thank you!")
 }
 } }
  • 54.
    Kotlin Android Extensions importkotlinx.android.synthetic.activity_main.click_me_button
 
 public class MainActivity : Activity() {
 
 override fun onCreate(savedInstanceState: Bundle?) {
 super.onCreate(savedInstanceState)
 setContentView(R.layout.activity_main)
 
 click_me_button.onClick {
 toast("Thank you!")
 }
 } }
  • 55.
    Anko: Android UIBuilders tableLayout {
 for (location in locations) {
 tableRow {
 textView(text = location.name)
 .lparams(column = 1)
 }
 }
 }
  • 56.
    Kotlin in theCommunity
  • 57.
    How to succeed
 with Kotlin 57
  • 58.
  • 59.
    Take initiative • Kotlinis not a silver bullet and not a magical solution for the problems of your project • Kotlin makes you more productive and your work more enjoyable • Try it and share the results with your teammates 59
  • 60.
    Don’t wait fora new project • Kotlin can be easily integrated into existing Java codebases 60
  • 61.
    Where to startusing Kotlin • Tests - OK not informative • Plugins and utilities - better • Core and frameworks - best 61
  • 62.
    Don’t fear thelearning curve • At JetBrains, summer interns become productive with Kotlin very quickly and deliver great results 62
  • 63.
    Use the Javato Kotlin converter • Convert only the classes that you’re going to modify • Cleanup and refactor the code produced by the converter 63
  • 64.
    Use the Javato Kotlin converter 64
  • 65.
    Summary • JetBrains entruststhe most business-critical tasks to Kotlin • Kotlin works great for both server-side and Android development • Take initiative and start using Kotlin today! 65
  • 67.