Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin in production for 2 years, my learnings

Kotlin in production for 2 years, my learnings

Pascal Welsch

June 12, 2017
Tweet

More Decks by Pascal Welsch

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. How I started with Kotlin • Started writing new features

    in Kotlin • Migrated code (mostly manually)
  4. • 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
  5. Gradle Plugin • Fast releases when Android Studio upgrades ◦

    Will get better with the official support • Better use
  6. 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
  7. Mixing Kotlin and Java • Calling back and forth works!

    • NullPointerException still possible when using Java libs • Don’t use retrolambda for Interfaces in Kotlin
  8. Multi dimensional arrays • Manual initialization required was required •

    Kind of a bummer when starting • New initializer function added in Kotlin 1.1
  9. 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
  10. 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
  11. Annotations processors • Completely unstable. Kapt barely works, only works

    every 5. Release • I stopped using Dagger2 -> Migrated to KoDeIn
  12. 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
  13. 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
  14. Public by default • I would prefer internal by default

    • I always forget private for properties
  15. Testing library • I’m still using AssertJ ◦ >5 assertion

    libs out there, non dominates, not really better • Mockito-kotlin helps with generics
  16. Use IntelliJ for non Android projects • AS 2.3 has

    problems running tests for pure kotlin projects
  17. 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
  18. 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
  19. JVM is stable • I tried Swift with generics and

    got a segmentation fault • I started to love the JVM