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

Kotlin for the Masses

Kotlin for the Masses

This is a presentation/meditation on the new Multiplatform Support in Kotlin 1.2.0. The talk was presented at @Honeypotio Amsterdam (06.12.2017). The video should be up shortly.

Serj Lotutovici

December 06, 2017
Tweet

More Decks by Serj Lotutovici

Other Decks in Programming

Transcript

  1. @SerjLtt Kotlin? data class MyClass(val prop: String) val myClass =

    MyClass(“something") val myClass2 = MyClass(null)
  2. @SerjLtt Kotlin? data class MyClass(val prop: String) val myClass =

    MyClass(“something") val myClass2 = MyClass(null)
  3. @SerjLtt Kotlin? fun foo() { } fun bar() = "bar"

    fun <T> Iterable<T>.tail() = drop(1)
  4. @SerjLtt Kotlin? fun foo() { } fun bar() = "bar"

    fun <T> Iterable<T>.tail() = drop(1) fun <R> (() -> R).run(): R = invoke()
  5. @SerjLtt Kotlin? fun foo() { } fun bar() = "bar"

    fun <T> Iterable<T>.tail() = drop(1) fun <R> (() -> R).run(): R = invoke() fun <R> fooBar(block: () -> R): R = block()
  6. @SerjLtt Kotlin? • Typesafe • Nullsafe • Modern & Concise

    • Functional (?) • Interoperable (!)
  7. @SerjLtt Kotlin? • Typesafe • Nullsafe • Modern & Concise

    • Functional (?) • Interoperable (!) • Allows for DSL creation
  8. @SerjLtt Kotlin? • Typesafe • Nullsafe • Modern & Concise

    • Functional (?) • Interoperable (!) • Allows for DSL creation • Find more @ kotlinlang.org
  9. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools
  10. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries
  11. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons
  12. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons
  13. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons • Too verbose
  14. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons • Too verbose • Slow language evolution (*)
  15. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons • Too verbose • Slow language evolution (*) • Misconceptions that the platform is old (&| dying)
  16. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons • Too verbose • Slow language evolution (*) • Misconceptions that the platform is old (&| dying)
  17. @SerjLtt Why Kotlin? Pros • Secure & Reliable • Huge

    open source community • ∞ Tools • ∞ Libraries Cons • Too verbose • Slow language evolution (*) • Misconceptions that the platform is old (&| dying) • [Android] Stuck on Java 6/7
  18. @SerjLtt Why Kotlin? Pros • Relatively easy to learn •

    Run’s on every browser (*) • ∞ Frameworks (*)
  19. @SerjLtt Why Kotlin? Pros • Relatively easy to learn •

    Run’s on every browser (*) • ∞ Frameworks (*) Cons
  20. @SerjLtt Why Kotlin? Pros • Relatively easy to learn •

    Run’s on every browser (*) • ∞ Frameworks (*) Cons
  21. @SerjLtt Why Kotlin? Pros • Relatively easy to learn •

    Run’s on every browser (*) • ∞ Frameworks (*) Cons • Not type safe
  22. @SerjLtt Why Kotlin? Pros • Relatively easy to learn •

    Run’s on every browser (*) • ∞ Frameworks (*) Cons • Not type safe • Callback based (*)
  23. @SerjLtt Why Kotlin? Pros • Relatively easy to learn •

    Run’s on every browser (*) • ∞ Frameworks (*) Cons • Not type safe • Callback based (*) • Is being pushed beyond the browser
  24. @SerjLtt Project? interface DataStore { fun data(): Data } class

    AndroidDataStore(private val db: RoomDatabase) : DataStore { override fun data() = TODO() }
  25. @SerjLtt Project? interface DataStore { fun data(): Data } class

    AndroidDataStore(private val db: RoomDatabase) : DataStore { override fun data() = TODO() } class IosDataStore(private val db: CoreData) : DataStore { override fun data() = TODO() }
  26. @SerjLtt Project? interface DataStore { fun data(): Data } class

    AndroidDataStore(private val db: RoomDatabase) : DataStore { override fun data() = TODO() } class IosDataStore(private val db: CoreData) : DataStore { override fun data() = TODO() } import org.w3c.dom.Storage class WebDataStore(private val store: Storage): DataStore { override fun data() = TODO() }
  27. @SerjLtt Kotlin Multiplatform Support // common/build.gradle apply plugin: 'kotlin-platform-common' dependencies

    { compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}" }
  28. @SerjLtt Kotlin Multiplatform Support // common/build.gradle apply plugin: 'kotlin-platform-common' dependencies

    { compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}" } // jvm/build.gradle
  29. @SerjLtt Kotlin Multiplatform Support // common/build.gradle apply plugin: 'kotlin-platform-common' dependencies

    { compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}" } // jvm/build.gradle apply plugin: 'kotlin-platform-jvm'
  30. @SerjLtt Kotlin Multiplatform Support // common/build.gradle apply plugin: 'kotlin-platform-common' dependencies

    { compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}" } // jvm/build.gradle apply plugin: 'kotlin-platform-jvm' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlin_version}" }
  31. @SerjLtt Kotlin Multiplatform Support // common/build.gradle apply plugin: 'kotlin-platform-common' dependencies

    { compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}" } // jvm/build.gradle apply plugin: 'kotlin-platform-jvm' dependencies { expectedBy project(':common') compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlin_version}" }
  32. @SerjLtt Kotlin Multiplatform Support // common expect class Printer(message: String)

    { fun print() } // jvm class Printer(private val message: String) { fun print() { println(message) } }
  33. @SerjLtt Kotlin Multiplatform Support // common expect class Printer(message: String)

    { fun print() } // jvm actual class Printer actual constructor(private val message: String) { actual fun print() { println(message) } }
  34. @SerjLtt Kotlin Multiplatform Support // common expect class Printer(message: String)

    { fun print() } // jvm actual class Printer actual constructor(private val message: String) { actual fun print() { println(message) } }
  35. @SerjLtt Kotlin Multiplatform Support // common expect class Printer(message: String)

    { fun print() } // jvm actual class Printer actual constructor(private val message: String) { actual fun print() { println(message) } }
  36. @SerjLtt Kotlin Multiplatform Support // common expect class Printer(message: String)

    { fun print() } // jvm actual class Printer actual constructor(private val message: String) { actual fun print() { println(message) } }
  37. @SerjLtt Kotlin Multiplatform Support // common expect abstract class Observable<T>

    { fun <R> map(f: Function<in T, out R>): Observable<R> }
  38. @SerjLtt Kotlin Multiplatform Support // common expect abstract class Observable<T>

    { fun <R> map(f: Function<in T, out R>): Observable<R> } expect interface Function<T, R> { fun apply(t: T): R }
  39. @SerjLtt Kotlin Multiplatform Support // common expect abstract class Observable<T>

    { fun <R> map(f: Function<in T, out R>): Observable<R> } expect interface Function<T, R> { fun apply(t: T): R } // jvm
  40. @SerjLtt Kotlin Multiplatform Support // common expect abstract class Observable<T>

    { fun <R> map(f: Function<in T, out R>): Observable<R> } expect interface Function<T, R> { fun apply(t: T): R } // jvm actual typealias Observable<T> = io.reactivex.Observable<T>
  41. @SerjLtt Kotlin Multiplatform Support // common expect abstract class Observable<T>

    { fun <R> map(f: Function<in T, out R>): Observable<R> } expect interface Function<T, R> { fun apply(t: T): R } // jvm actual typealias Observable<T> = io.reactivex.Observable<T> actual typealias Function<T, R> = io.reactivex.functions.Function<T, R>
  42. @SerjLtt Should I try Kotlin? •Kotlin JVM (`kotlin`) •Kotlin Js

    (`kotlin-js`) - stable since 1.1.x •Kotlin Android (`kotlin-android`) - backed by Google
  43. @SerjLtt Should I try Kotlin? •Kotlin JVM (`kotlin`) •Kotlin Js

    (`kotlin-js`) - stable since 1.1.x •Kotlin Android (`kotlin-android`) - backed by Google •Gradle Script Kotlin
  44. @SerjLtt Should I try Kotlin? •Kotlin JVM (`kotlin`) •Kotlin Js

    (`kotlin-js`) - stable since 1.1.x •Kotlin Android (`kotlin-android`) - backed by Google •Gradle Script Kotlin •Kotlin Native (*) - currently 0.4
  45. @SerjLtt Final Thoughts •One language for all platforms/teams/universes •Better communication

    between teams (*) •No man in the middle, just you and your platform (*)
  46. @SerjLtt Final Thoughts •One language for all platforms/teams/universes •Better communication

    between teams (*) •No man in the middle, just you and your platform (*) •Shared code/vision/ideas