$30 off During Our Annual Pro Sale. View Details »

Why I Left Java for Kotlin

Why I Left Java for Kotlin

Sam Edwards

July 21, 2020
Tweet

More Decks by Sam Edwards

Other Decks in Programming

Transcript

  1. Why I Left Java
    For Kotlin
    Sam Edwards - @HandstandSam

    View Slide

  2. Sam Edwards

    View Slide

  3. Outline
    ●The Current State of Java & Kotlin

    ●Live Coding - Kotlin Language Features

    ●What Else is Possible with Kotlin

    ●Conclusion

    View Slide

  4. I Love Java

    View Slide

  5. My First…
    • Job out of college was writing Java
    • Google App Engine Backend
    • Android app was written in Java

    View Slide

  6. Java 6?
    Who is Using "

    View Slide

  7. Java 7?
    Who is Using
    #
    $

    View Slide

  8. Java 8?
    Who is Using
    &$
    '()
    #'

    View Slide

  9. Java 9,10,11,12,13,14?
    Who is Using
    *

    View Slide

  10. Java Releases
    https://en.wikipedia.org/wiki/Java_version_history
    10

    View Slide

  11. Java Releases
    11
    J2SE 1.4 February 2002
    J2SE 5.0 September 2004
    Java SE 6 December 2006
    Java SE 7 July 2011
    Java SE 8 (LTS) March 2014
    Java SE 9 September 2017
    Java SE 10 March 2018
    Java SE 11 (LTS) September 2018
    Java SE 12 March 2019
    Java SE 13 September 2019
    https://en.wikipedia.org/wiki/Java_version_history

    View Slide

  12. Kotlin

    View Slide

  13. Kotlin
    13

    View Slide

  14. Android Community Driven Adoption

    View Slide

  15. Officially Supported Language (2017)

    View Slide

  16. Preferred Language for Android (2019)

    View Slide

  17. 17

    View Slide

  18. View Slide

  19. View Slide

  20. Kotlin Releases
    • Started - 2010

    • 1.0 - 2016

    • 1.1 - 2017

    • 1.2 - 2017

    • 1.3 - 2018

    • 1.4 - Almost… 2020…

    View Slide

  21. Fast Evolution of Kotlin
    ●Decoupled From Java Virtual Machine (JVM)

    ●Compiler Plugin + Standard Libraries -> Java Bytecode

    View Slide

  22. View Slide

  23. 23

    View Slide

  24. It’s The Little Things

    View Slide

  25. View Slide

  26. Why I Left Java for Kotlin - Live Coding
    https://github.com/handstandsam/why-i-left-java-for-kotlin

    View Slide

  27. My Favorite Features
    ●Java Interop

    ●Extension Functions

    ●Ability to Convert Java -> Kotlin

    ●Null Safety

    ●Data Classes

    ●Immutability (val)

    ●Named Parameters

    ●No “new” or “;”

    ●Higher Order Functions & Lambdas

    ●Sealed Classes

    ●Coroutines - Reactive Programming

    View Slide

  28. Coroutines

    View Slide

  29. Kotlin Coroutines
    Explained in one slide
    • A function with a suspend keyword signifies it must run in a Coroutine


    suspend fun doNetworkRequest() : Result {

    // Network Request Occurs

    }

    • suspend functions must be executed within a CoroutineContext and Once
    inside a coroutine, code executes sequentially


    CoroutineContext(Dispatchers.Default).launch{

    val result = doNetworkRequest()

    processResult(result)

    }

    View Slide

  30. “Essentially, coroutines are light-weight
    threads. They are launched in a context
    of some CoroutineScope.”

    View Slide

  31. “Essentially, coroutines are light-weight
    threads. They are launched in a context
    of some CoroutineScope.”

    View Slide

  32. (Developer) Happiness

    View Slide

  33. Developer Happiness is REAL

    View Slide

  34. Developer Happiness
    ●Less Boilerplate

    ●Concise & Readable Code

    ●Handle Nullable Values Proactively

    ●Don’t have to throw away Java code

    ●Enables Functional Programming

    ●Enables Reactive Programming

    View Slide

  35. Kotlin Adoption

    View Slide

  36. GitHub Repositories Created in 2020
    ● Java: 1,034,837

    https://github.com/search?q=created%3A%3E2019-01-01+language%3AJava&type=Repositories&ref=advsearch&l=Java&l=


    ● Kotlin: 100,798 

    https://github.com/search?q=created%3A%3E2020-01-01+language%3Akotlin&type=Repositories

    View Slide

  37. What Else is Possible with Kotlin?

    View Slide

  38. Kotlin Multiplatform
    ●Android + iOS Code Sharing

    ●JavaScript

    ●Mac, Linux, Window

    View Slide

  39. Multiplatform Libraries
    https://github.com/AAkira/Kotlin-Multiplatform-Libraries

    View Slide

  40. Kotlin Native

    View Slide

  41. Not All Roses

    View Slide

  42. Not All Roses
    ●Non-Ideal Interop For Some Java Frameworks and
    Libraries

    ●Pick the right tool for the job

    ●Not everyone knows Kotlin yet

    ●Your team may not want to do Kotlin because it’s too
    “risky”

    View Slide

  43. I Love Kotlin

    View Slide

  44. Dear Java,

    You taught me about NullPointerExceptions, verbose
    code and mutable data. I will always love you, but
    I’ve met a language named Kotlin, and I’m moving on.

    Love,

    -Sam

    View Slide

  45. Why I Left Java

    For Kotlin
    Sam Edwards - @HandstandSam
    Thank You!

    View Slide

  46. View Slide

  47. Kotlin to Java Bytecode

    View Slide

  48. Kotlin Compilation to Java Bytecode
    Code.kt Code.class
    Kotlin Compiler

    View Slide

  49. Java Decompiler (Using Fernflower)
    Code.class Java Decompiler Code.java

    View Slide

  50. Magic
    Code.kt Code.class
    Kotlin Compiler Java Decompiler Code.java

    View Slide

  51. Code.kt Code.class
    Kotlin
    Compiler
    Java
    Decompiler
    Code.java

    View Slide