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

Is Kotlin Ready for Android

Is Kotlin Ready for Android


Peter-John Welcome

July 20, 2017

More Decks by Peter-John Welcome

Other Decks in Technology


  1. Is Kotlin Ready for Android Peter-John Welcome @pjapplez

  2. Google announced Kotlin will be an official language for Android

  3. Kotlin Was born in 2011 by JetBrains Team • Modern

    • Expressive • Magical • Powerful • Concise • Extensible https://en.wikipedia.org/wiki/Kotlin_(programming_language)
  4. Kotlin • Small runtime • Statically typed language • Modern

    language • Runs on JVM and converts to Java byte code • Reduces errors and boiler plate code • Composition over inheritance
  5. Why Kotlin over Java • We still on Java 6.5

    in Android • Java Code is error Prone with all its anonymous inner classes • Java Language Restriction ( lambdas , Default Interfaces … etc ) • Java code is very verbose.
  6. What Java doesn’t have • High-order functions • Properties •

    Extension functions • Static null checks • Auto casting/Smart casting • Default parameters • String interpolation • Pattern matching • Inline functions • Infix methods
  7. Android’s Root Problem https://image.slidesharecdn.com/droidcon-bugsense-130408170720-phpapp01/95/droid-con-bugsense-16-638.jpg?cb=1365440918

  8. "I call it my billion-dollar mistake... [which] has led to

    innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years." — Sir Charles Antony Richard Hoare Nullability https://blog.valbonne-consulting.com/2014/11/26/tony-hoare-invention-of-the-null-reference-a-billion-dollar-mistake/
  9. var a: String = "foo" a = null //Compilation error

    var b: String? = "bar" b = null //ok Nullability
  10. val user = User() // there's no 'new' keyword in

    Kotlin user.name = "PJ" Properties
  11. inline fun SharedPreferences.edit(action: SharedPreferences.Editor() -> Unit) { val editor =

    SharedPreferences.Editor() editor.action() editor.apply() } getSharedPreferences(MODE_PRIVATE).edit { putString("username", username) } Extension Functions for Android
  12. Anko • Anko Commons: a lightweight library full of helpers

    for intents, dialogs, logging and so on; • Anko Layouts: a fast and type-safe way to write dynamic Android layouts; • Anko SQLite: a query DSL and parser collection for Android SQLite; • Anko Coroutines: utilities based on the kotlinx.coroutines library.
  13. Should we be on the Kotlin Train? Most Definitely !!!!

  14. Kotlin advantages • Less crashes • Easier to develop in

    • Encourages functional paradigm • 100 % Interoperable with Java ( Can use within existing code base.)
  15. Kotlin Community

  16. Resources • https://blog.mindorks.com/a-complete-guide-to-learn-kotlin-for-android-development-b1e5d23 cc2d8 • https://leanpub.com/kotlin-for-android-developers • https://developer.android.com/kotlin/index.html • https://kotlinlang.org/docs/tutorials/kotlin-android.html

  17. Thanks! Contact me: google.com/u/0/+PeterJohnWelcome @pjapplez pjwelcome@gmail.com Peter-johnwelcome.co.za https://github.com/pjwelcome