Kotlin in
production
One year later
Pascal Welsch, grandcentrix GmbH
Slide 3
Slide 3 text
Our existing JVM languages are great, but none of them have
demonstrated the potential to become the de facto language of
choice for a large percentage of JVM developers.
- Joe Kutner - Heroku
Slide 4
Slide 4 text
No content
Slide 5
Slide 5 text
How I started with Kotlin
● Read the documentation
● Did the Kotlin Kohans
● Solved a few coding challenges with kotlin
○ Google Code Jam
○ Advent of Code
● Kotlin Slack community is very helpful
● Convert Java code to learn how to write it in Kotlin
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
How I started with Kotlin
● Started writing new features in Kotlin
● Migrated code (mostly manually)
Slide 8
Slide 8 text
● Wohin Du Willst - Android App - live
○ Existing project written in java
● Nearby Debugger - Android App - live
○ Small app entirely in kotlin
● Internal Technical Prototype - Android App - not released
○ 98% in kotlin
● GitVersioner Plugin - Gradle Plugin - live
○ Written in kotlin
● Current Client Project - Android App - not released
○ Pure kotlin
Last years projects
Slide 9
Slide 9 text
Gradle Plugin
● Fast releases when Android Studio upgrades
○ Will get better with the official support
● Better use
Slide 10
Slide 10 text
Kotlin major releases
● No pain!
● Works 99% on day 1
● Long EAP and beta program
● Tip: Don’t upgrade on day 1, wait for patch 1 or 2
Mixing Kotlin and Java
● Calling back and forth works!
● NullPointerException still possible when using Java
libs
● Don’t use retrolambda for Interfaces in Kotlin
Slide 14
Slide 14 text
Lambdas <3
● So much better than Java lambdas
Slide 15
Slide 15 text
Multi dimensional arrays
● Manual initialization required was required
● Kind of a bummer when starting
● New initializer function added in Kotlin 1.1
Slide 16
Slide 16 text
Data classes
Slide 17
Slide 17 text
Keep Multithreading in mind
Slide 18
Slide 18 text
Keep Multithreading in mind
Slide 19
Slide 19 text
Keep Multithreading in mind
Slide 20
Slide 20 text
Keep Multithreading in mind
Slide 21
Slide 21 text
Keep Multithreading in mind
Slide 22
Slide 22 text
No static
● Global variable definitions
● Global function definitions
● Global objects
● Companion objects
● Except for Java, most languages have a way to declare
constants without wrapping them in a class
Slide 23
Slide 23 text
No static
Slide 24
Slide 24 text
No SAM conversion for Kotlin
interfaces
● Solutions:
○ write two methods, one for kotlin, one for Java
○ Return Unit in Java code
○ Write Interfaces in Java
● Most requested feature in recent developer survey
Slide 25
Slide 25 text
No SAM
conversion
for Kotlin
interfaces
Slide 26
Slide 26 text
Properties
● No getters, setters required (optional)
● Properties can by dynamic
Slide 27
Slide 27 text
Properties
Slide 28
Slide 28 text
Optional and named
Parameters
Slide 29
Slide 29 text
Annotations processors
● Completely unstable. Kapt barely works, only works every
5. Release
● I stopped using Dagger2 -> Migrated to KoDeIn
Slide 30
Slide 30 text
KoDeIn
Slide 31
Slide 31 text
Reified Generics
● Makes injection easy
Slide 32
Slide 32 text
Protobuf code generation
● compile task order of protobuf plugin for doesn’t work with
kotlin plugin
● Can’t reference Protobuf classes from Kotlin code
● Solution: Separate module for Protobuf code required
Slide 33
Slide 33 text
Bit shifting
● Handling low level bits and bytes in Java was annoying
● It got worse in Kotlin
● Extension functions help a lot
● Jetbrains is working on better bit shifting syntax and
unsigned data types
Slide 34
Slide 34 text
Extension functions
● Use a ActivityExt.kt file for Activity extension function
● Use private where possible
Slide 35
Slide 35 text
Public by default
● I would prefer internal by default
● I always forget private for properties
Slide 36
Slide 36 text
Testing library
● I’m still using AssertJ
○ >5 assertion libs out there, non dominates, not really better
● Mockito-kotlin helps with generics
Slide 37
Slide 37 text
Use IntelliJ for non Android
projects
● AS 2.3 has problems running tests for pure kotlin projects
Slide 38
Slide 38 text
Adoption of Kotlin at
grandcentrix
● We had a GO from management to use Kotlin in all projects
one week before it was officially adopted by Google
● Now we roll it out in all active projects over the next
months
● Starting with Unit Tests and new features
Slide 39
Slide 39 text
Coroutines
● Beta in Kotlin 1.1
● Cool idea for async/await implementations
● Useful for server side code to replace Promises
● On Android RxJava is a better fit than coroutines
Slide 40
Slide 40 text
DSL feature
● Gradle scripts can be written with kotlin (.kts)
Slide 41
Slide 41 text
Kotlin libraries
● Write Android libraries in Java
● Maybe release a separate kt artifact
Slide 42
Slide 42 text
JVM is stable
● I tried Swift with generics and got a segmentation fault
● I started to love the JVM