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

Kotlin > 🏝 (Kotlin: more than an island)

Kotlin > 🏝 (Kotlin: more than an island)

2017-07-15: MobileOptimized 2017
2017-05-31: https://www.meetup.com/GDG-Berlin-Android/events/238173227

The last Google I/O was probably the most exciting ever, especially for one reason: Kotlin received official recognition as a first-class citizen on Android.
The quantity of developers cheering for this shouldn't come as a surprise, as some of them have already been using the language for years, and for good reasons.
Join us to understand what Kotlin really is, and witness how its principles and advanced features make it so unique today, plus what will make it transcend into something even more powerful in the future.

Animated slides (Keynote): https://goo.gl/QfQLdp

Eugenio Marletti

May 31, 2017
Tweet

More Decks by Eugenio Marletti

Other Decks in Technology

Transcript

  1. !

    View Slide

  2. !
    “…Kotlin is a new JVM language…”

    View Slide

  3. !
    “…Kotlin is a new JVM language…”

    View Slide

  4. !
    “…Kotlin is a new JVM language…”

    View Slide

  5. View Slide

  6. View Slide

  7. made by JetBrains
    open source, non-profit foundation
    pragmatic
    safe(r than Java)
    “good” magic ✨
    FUN

    View Slide

  8. packages
    optional
    no need to match folder
    files
    multiple classes
    top level functions

    View Slide

  9. // src/main/kotlin/covfefe/Whatever.kt
    fun main(args: Array) {
    }
    println("Hello World!")

    View Slide

  10. fun main(args: Array) {
    val immutable = 0
    immutable += 1
    }

    View Slide

  11. fun main(args: Array) {
    var mutable = 0
    mutable += 1
    }

    View Slide

  12. fun main(args: Array) {
    val nullable: String? = null
    val alternative = nullable ?: "¯\_(ϑ)_/¯"
    val lengthOrNull = nullable?.length
    if (nullable != null) {
    println(nullable.length)
    }
    }
    }

    View Slide

  13. fun Int.twice() = this * 2
    fun test() = 1.twice() // 2

    View Slide

  14. inline fun Map.getOrElse(
    key: K,
    defaultValue: () -> V
    ) =
    get(key) ?: defaultValue()

    View Slide

  15. abstract class NetworkResult {
    object Cancelled : NetworkResult()
    data class Success(val json: String) : NetworkResult()
    data class Error(val error: Throwable) : NetworkResult()
    }
    fun test(result : NetworkResult) = when (result) {
    NetworkResult.Cancelled -> null
    is NetworkResult.Success -> result.json
    is NetworkResult.Error -> throw result.error
    else -> error("WTF")
    }

    View Slide

  16. sealed
    object Cancelled : NetworkResult()
    data class Success(val json: String) : NetworkResult()
    data class Error(val error: Throwable) : NetworkResult()
    }
    fun test(result : NetworkResult) = when (result) {
    NetworkResult.Cancelled -> null
    is NetworkResult.Success -> result.json
    is NetworkResult.Error -> throw result.error
    class NetworkResult {
    }

    View Slide

  17. why?

    View Slide

  18. everything you can do in Kotlin can be done in Java

    View Slide

  19. everything you can do in Java can be done in bytecode

    View Slide

  20. high level abstractions, enforced by the compiler
    extend the language through DSL
    built in symbiosis with tools
    moving fast, but carefully
    change of mindset

    View Slide

  21. myths

    View Slide

  22. slow compilation
    runtime overhead
    learning curve
    not knowing what’s really going on
    confusing without IDE

    View Slide

  23. cons

    View Slide

  24. occasional rough edges around tooling
    not being able to go back to Java, ever

    View Slide

  25. future

    View Slide

  26. immutable collections
    universal serialization
    type classes
    multiplatform
    metaprogramming

    View Slide

  27. Official website
    goo.gl/xL99fk
    Kotlin and Android (blog)
    goo.gl/FQYAcW
    Introduction to Kotlin (video)
    goo.gl/3n6wic
    Life is Great and Everything Will Be Ok, Kotlin is Here (video)
    goo.gl/NTaYqi
    Using Project Kotlin for Android (doc)
    goo.gl/T0SDTJ
    The Future of Kotlin (video)
    goo.gl/INLPDl
    Kotlin 1.1 (video)
    goo.gl/iKojmn

    View Slide

  28. BIT
    .LY
    /KO
    TLIN
    -M
    O
    RE
    -TH
    A
    N
    -A
    N
    -ISLA
    N
    D
    Eugenio
    Marletti
    @workingkills

    View Slide