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
Tweet

More Decks by Peter-John Welcome

Other Decks in Technology

Transcript

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

    • Expressive • Magical • Powerful • Concise • Extensible https://en.wikipedia.org/wiki/Kotlin_(programming_language)
  2. 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
  3. 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.
  4. 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
  5. "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/
  6. var a: String = "foo" a = null //Compilation error

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

    Kotlin user.name = "PJ" Properties
  8. 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
  9. 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.
  10. Kotlin advantages • Less crashes • Easier to develop in

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