Slide 1

Slide 1 text

Our Journey from Java to Kotlin-first! Pablo Guardiola @Guardiola31337

Slide 2

Slide 2 text

Navigation SDK 1.0 - Kotlin-first - Modularized - Clean and performant APIs that are hard to misuse

Slide 3

Slide 3 text

Episode 1. Kotlin

Slide 4

Slide 4 text

SDKs

Slide 5

Slide 5 text

SIZE

Slide 6

Slide 6 text

SIZE & Number of methods Too many field references: max is 65536

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Show me the numbers!!!

Slide 9

Slide 9 text

Kotlin stdlib increased the apk size by around 380 KB and added around 6K methods

Slide 10

Slide 10 text

Nope.

Slide 11

Slide 11 text

Benefits Developer - Intuitive - Statically typed - Type inference - Outstanding IDE support - Functional and object-oriented - Expressive - Concise - null safe - //.

Slide 12

Slide 12 text

Client / User - More strongly typed than Java - DSLs - Modern, powerful and safe - Fewer methods, less weight Benefits

Slide 13

Slide 13 text

Nope.

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

30.5% SDK / Libraries

Slide 17

Slide 17 text

77% Extension functions

Slide 18

Slide 18 text

Nope.

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Nope.

Slide 22

Slide 22 text

Navigation SDK

Slide 23

Slide 23 text

YES - Still in Beta (0.x) - Young - Client apps in Kotlin - Excitement

Slide 24

Slide 24 text

All in on Kotlin or not? Sep 2019

Slide 25

Slide 25 text

NO - stdlib adds binary size - Kotlin versions incompatibility - Extra effort to make APIs Java friendly

Slide 26

Slide 26 text

YES - Google’s preferred language for Android - Productivity - New Java features adoption is slow - OkHttp (v4.x) - Concurrency - Hiring

Slide 27

Slide 27 text

Oct 8, 2019

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Episode 2. Conversion

Slide 30

Slide 30 text

Code style ktlint

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

@NonNull and @Nullable annotations Analyze > Infer Nullity//.

Slide 33

Slide 33 text

Convert Java to Kotlin ⌥⇧⌘K

Slide 34

Slide 34 text

Polish Kotlin code

Slide 35

Slide 35 text

if null else / let Elvis operator

Slide 36

Slide 36 text

if null else / let Elvis operator

Slide 37

Slide 37 text

switch / when

Slide 38

Slide 38 text

switch / when

Slide 39

Slide 39 text

callback

Slide 40

Slide 40 text

callback

Slide 41

Slide 41 text

Utils

Slide 42

Slide 42 text

Special attention - /! - lateinit / lazy - @NotNull non-annotated parameters - @JvmStatic and @get: - @throws methods - Writing Java in Kotlin

Slide 43

Slide 43 text

MockK - relaxed = true RETURNS_DEEP_STUBS - relaxedUnitFun = true - Kotlin idiomatic - mockkObject - mockkStatic

Slide 44

Slide 44 text

Episode 3. 1.0

Slide 45

Slide 45 text

Public APIs - Don’t expose Kotlin types - Great for both Java and Kotlin - Java and Kotlin examples - Master @Jvm annotations - Rest of the code internal

Slide 46

Slide 46 text

To be continued//.

Slide 47

Slide 47 text

Takeaways - El que la sigue la consigue (Keep insisting) - Baby steps - Test harness - Watch out null checks - Designing Good APIs is hard

Slide 48

Slide 48 text

Thanks.

Slide 49

Slide 49 text

Questions? Pablo Guardiola @Guardiola31337

Slide 50

Slide 50 text

Sources https://realm.io/realm-report/2017-q4/ https://pusher.com/state-of-kotlin https://developer.squareup.com/blog/okio-2 https://mockk.io/