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

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. Is Kotlin Ready for Android
    Peter-John Welcome
    @pjapplez

    View Slide

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

    View Slide

  3. Kotlin
    Was born in 2011 by JetBrains Team
    ● Modern
    ● Expressive
    ● Magical
    ● Powerful
    ● Concise
    ● Extensible
    https://en.wikipedia.org/wiki/Kotlin_(programming_language)

    View Slide

  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

    View Slide

  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.

    View Slide

  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

    View Slide

  7. Android’s Root Problem
    https://image.slidesharecdn.com/droidcon-bugsense-130408170720-phpapp01/95/droid-con-bugsense-16-638.jpg?cb=1365440918

    View Slide

  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/

    View Slide

  9. var a: String = "foo"
    a = null //Compilation error
    var b: String? = "bar"
    b = null //ok
    Nullability

    View Slide

  10. val user = User() // there's no 'new' keyword in Kotlin
    user.name = "PJ"
    Properties

    View Slide

  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

    View Slide

  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.

    View Slide

  13. Should we be on the Kotlin Train?
    Most Definitely !!!!

    View Slide

  14. Kotlin advantages
    ● Less crashes
    ● Easier to develop in
    ● Encourages functional paradigm
    ● 100 % Interoperable with Java ( Can use within existing code base.)

    View Slide

  15. Kotlin Community

    View Slide

  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

    View Slide

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

    View Slide