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. !
    “…Kotlin is a new JVM language…”

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  12. 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 full-size slide

  13. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  16. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  19. immutable collections
    universal serialization
    type classes
    multiplatform
    metaprogramming

    View full-size slide

  20. 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 full-size slide

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

    View full-size slide