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

Why I Left Java for Kotlin

Why I Left Java for Kotlin

5701f31a8433a22ae736282de8d08cd6?s=128

Sam Edwards

July 21, 2020
Tweet

Transcript

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

  2. Sam Edwards

  3. Outline •The Current State of Java & Kotlin •Live Coding

    - Kotlin Language Features •What Else is Possible with Kotlin •Conclusion
  4. I Love Java ❤

  5. My First… • Job out of college was writing Java

    • Google App Engine Backend • Android app was written in Java
  6. Java 6? Who is Using "

  7. Java 7? Who is Using # $

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

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

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

  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
  12. Kotlin

  13. Kotlin 13

  14. Android Community Driven Adoption

  15. Officially Supported Language (2017)

  16. Preferred Language for Android (2019)

  17. 17

  18. None
  19. None
  20. Kotlin Releases • Started - 2010 • 1.0 - 2016

    • 1.1 - 2017 • 1.2 - 2017 • 1.3 - 2018 • 1.4 - Almost… 2020…
  21. Fast Evolution of Kotlin •Decoupled From Java Virtual Machine (JVM)

    •Compiler Plugin + Standard Libraries -> Java Bytecode
  22. None
  23. 23

  24. It’s The Little Things

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

  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
  28. Coroutines

  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)
 }
  30. “Essentially, coroutines are light-weight threads. They are launched in a

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

    context of some CoroutineScope.”
  32. (Developer) Happiness

  33. Developer Happiness is REAL

  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
  35. Kotlin Adoption

  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
  37. What Else is Possible with Kotlin?

  38. Kotlin Multiplatform •Android + iOS Code Sharing •JavaScript •Mac, Linux,

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

  40. Kotlin Native

  41. Not All Roses

  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”
  43. I Love Kotlin ❤

  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
  45. Why I Left Java For Kotlin Sam Edwards - @HandstandSam

    Thank You!
  46. None
  47. Kotlin to Java Bytecode

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

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

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

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