Kotlin in production for 2 years, my learnings

Kotlin in production for 2 years, my learnings

F4cff86f26a0d63a0f5d20494e955c04?s=128

Pascal Welsch

June 12, 2017
Tweet

Transcript

  1. Welcome to GDG DUS July

  2. Kotlin in production One year later Pascal Welsch, grandcentrix GmbH

  3. 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
  4. None
  5. 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
  6. None
  7. How I started with Kotlin • Started writing new features

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

    Will get better with the official support • Better use
  10. 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
  11. Method count • org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3-2 ◦ 6317 • io.reactivex.rxjava2:rxjava:2.1.1 ◦ 10204

    • Io.reactivex:rxjava:1.3.0 ◦ 5751
  12. RxJava is harder to learn than Kotlin

  13. Mixing Kotlin and Java • Calling back and forth works!

    • NullPointerException still possible when using Java libs • Don’t use retrolambda for Interfaces in Kotlin
  14. Lambdas <3 • So much better than Java lambdas

  15. Multi dimensional arrays • Manual initialization required was required •

    Kind of a bummer when starting • New initializer function added in Kotlin 1.1
  16. Data classes

  17. Keep Multithreading in mind

  18. Keep Multithreading in mind

  19. Keep Multithreading in mind

  20. Keep Multithreading in mind

  21. Keep Multithreading in mind

  22. 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
  23. No static

  24. 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
  25. No SAM conversion for Kotlin interfaces

  26. Properties • No getters, setters required (optional) • Properties can

    by dynamic
  27. Properties

  28. Optional and named Parameters

  29. Annotations processors • Completely unstable. Kapt barely works, only works

    every 5. Release • I stopped using Dagger2 -> Migrated to KoDeIn
  30. KoDeIn

  31. Reified Generics • Makes injection easy

  32. 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
  33. 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
  34. Extension functions • Use a ActivityExt.kt file for Activity extension

    function • Use private where possible
  35. Public by default • I would prefer internal by default

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

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

    problems running tests for pure kotlin projects
  38. 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
  39. 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
  40. DSL feature • Gradle scripts can be written with kotlin

    (.kts)
  41. Kotlin libraries • Write Android libraries in Java • Maybe

    release a separate kt artifact
  42. JVM is stable • I tried Swift with generics and

    got a segmentation fault • I started to love the JVM
  43. Pascal Welsch @passsy grandcentrix.net @grandcentrix