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

Kotlin All The Things!

Kotlin All The Things!

Kotlin is taking the development community by storm. Since Google announced they are officially partnering with JetBrains to support the language for Android development, mobile developers are flocking en masse.

But what about everyone else? Good news - Kotlin is not just for mobile. In this talk, we will take a look at the overall landscape. For Java developers, we will look at Kotlin on the server. For Front End developers, we will check out Kotlin for JavaScript. For everyone else, we'll poke around Kotlin Native, which can compile Kotlin for platforms that don't have a virtual machine such as IOS.

Michael Yotive

April 12, 2019
Tweet

More Decks by Michael Yotive

Other Decks in Technology

Transcript

  1. Why All The Things? Kotlin All The Things • Save

    time/money ◦ Caution: Big investment • Sharing code within/across company • Increased Quality • Feature teams
  2. • Kotlin on the Server • Client Side Kotlin •

    Kotlin/Native • Kotlin Multiplatform Kotlin All The Things Agenda
  3. Kotlin on the Server Backend • Read dynamic data •

    Authenticate • Write/Persist data Kotlin All The Things
  4. Kotlin on the Server Why Kotlin? • Great Modern language

    ◦ Higher order functions ◦ Extension functions ◦ Type Safety ◦ Coroutines • Allows you to stay on Java 8 Kotlin All The Things
  5. Kotlin on the Server Kotlin All The Things KotlinConf 2018

    - Komparing Kotlin Server Frameworks by Ken Yee https://www.youtube.com/watch?v=8xfQA10Cd7g
  6. Spring and Spring Boot Kotlin All The Things What is

    Spring? • Most popular framework for building Java applications. • Flexible, modular, and backwards compatible • Aims at making development easier by reducing boilerplate. • Large and active community • Open Source, but back by a large company.
  7. Spring and Spring Boot Kotlin All The Things What is

    Spring Boot? • Another project built of top of Spring. • Main goals: ◦ Decrease friction by taking an opinionated approach to building applications ◦ Reduce configurations ◦ Streamline deployment approach
  8. Sample Kotlin All The Things @SpringBootApplication class DemoApplication fun main(args:

    Array<String>) { runApplication<DemoApplication>(*args) } @RestController class HelloWorldController{ @GetMapping("/") fun helloWorld() = "Hello World!" }
  9. Sample Kotlin All The Things @SpringBootApplication class DemoApplication fun main(args:

    Array<String>) { runApplication<DemoApplication>(*args) } @RestController class HelloWorldController{ @GetMapping("/") fun helloWorld() = "Hello World!" }
  10. Sample Kotlin All The Things @SpringBootApplication class DemoApplication fun main(args:

    Array<String>) { runApplication<DemoApplication>(*args) } @RestController class HelloWorldController{ @GetMapping("/") fun helloWorld() = "Hello World!" }
  11. Sample Kotlin All The Things @SpringBootApplication class DemoApplication fun main(args:

    Array<String>) { runApplication<DemoApplication>(*args) } @RestController class HelloWorldController{ @GetMapping("/") fun helloWorld() = "Hello World!" }
  12. Sample Kotlin All The Things @SpringBootApplication class DemoApplication fun main(args:

    Array<String>) { runApplication<DemoApplication>(*args) } @RestController class HelloWorldController{ @GetMapping("/") fun helloWorld() = "Hello World!" }
  13. Sample Kotlin All The Things data class SimpleObject(val data:String =

    "Sample") @RestController class HelloWorldController{ @GetMapping("/Sample") fun sample() = (1 .. 10).map { SimpleObject() } }
  14. Sample Kotlin All The Things data class SimpleObject(val data:String =

    "Sample") @RestController class HelloWorldController{ @GetMapping("/Sample") fun sample() = (1 .. 10).map { SimpleObject() } }
  15. Sample Kotlin All The Things data class SimpleObject(val data:String =

    "Sample") @RestController class HelloWorldController{ @GetMapping("/Sample") fun sample() = (1 .. 10).map { SimpleObject() } }
  16. KTor Kotlin All The Things • Jetbrain’s official server framework

    • Written in pure Kotlin using Coroutines • Unopinionated • Lots of features ◦ Websockets ◦ Authentication ◦ HTML Templates https://ktor.io/
  17. KTor Kotlin All The Things • Can be hosted on

    any Servlet 3.0+ API (such as TomCat) ◦ Supports standalone Netty and Jetty, too. • Includes a cross-platform HTTP Client that includes: ◦ Authentication (includes OAuth 1a and 2) ◦ Cookies ◦ WebSockets ◦ JSON Processing https://ktor.io/
  18. KTor Kotlin All The Things const val defaultPort = 8080

    fun main() { embeddedServer(Netty, defaultPort, module = Application::main) .start(wait = true) }
  19. KTor Kotlin All The Things const val defaultPort = 8080

    fun main() { embeddedServer(Netty, defaultPort, module = Application::main) .start(wait = true) }
  20. KTor Kotlin All The Things const val defaultPort = 8080

    fun main() { embeddedServer(Netty, defaultPort, module = Application::main) .start(wait = true) }
  21. KTor Kotlin All The Things fun Application.main(){ install(DefaultHeaders){ header("Access-Control-Allow-Origin", "*")

    } install(ContentNegotiation) { gson { setDateFormat(DateFormat.LONG) setPrettyPrinting() } } installRoutes() }
  22. KTor Kotlin All The Things fun Application.main(){ install(DefaultHeaders){ header("Access-Control-Allow-Origin", "*")

    } install(ContentNegotiation) { gson { setDateFormat(DateFormat.LONG) setPrettyPrinting() } } installRoutes() }
  23. KTor Kotlin All The Things fun Application.main(){ install(DefaultHeaders){ header("Access-Control-Allow-Origin", "*")

    } install(ContentNegotiation) { gson { setDateFormat(DateFormat.LONG) setPrettyPrinting() } } installRoutes() }
  24. KTor Kotlin All The Things fun Application.installRoutes() { routing {

    get("/") { ... } get("/sessions") { ... } get("/sessions/{id}") { ... } } }
  25. KTor Kotlin All The Things get("/") { call.respondHtml { head

    { title("Ping") } body { h1 { +"The API is up." } } } } https://github.com/Kotlin/kotlinx.html
  26. KTor Kotlin All The Things get("/") { call.respondHtml { head

    { title("Ping") } body { h1 { +"The API is up." } } } } https://github.com/Kotlin/kotlinx.html
  27. KTor Kotlin All The Things get("/sessions") { val sessions =

    SessionDB.sessionRepository.all() call.respond(sessions) }
  28. KTor Kotlin All The Things get("/sessions") { val sessions =

    SessionDB.sessionRepository.all() call.respond(sessions) }
  29. KTor Kotlin All The Things get("/sessions/{id}") { val sessionId =

    call.parameters["id"] val data = SessionDB.sessionRepository.find(Session::id eq sessionId) .firstOrDefault() call.respond(data) }
  30. KTor Kotlin All The Things get("/sessions/{id}") { val sessionId =

    call.parameters["id"] val data = SessionDB.sessionRepository.find(Session::id eq sessionId) .firstOrDefault() call.respond(data) }
  31. KTor Kotlin All The Things data class HelloWorld(val hello: String)

    post("/route") { val helloWorld = call.receive<HelloWorld>() }
  32. • kotlinc-js ◦ Available for use since Kotlin 1.1 ◦

    Validate and transpile Kotlin code to Javascript • Targets ECMAScript 5.1 ◦ Plans in the work to support ECMAScript 2015 Kotlin/JS Kotlin All The Things
  33. Goals • Output readable Javascript. • Produce Javascript that is

    optimal in size. • Optional interoperability with existing module systems: ◦ CommonJS (NodeJS) ◦ AMD (RequireJS) ◦ UMD Kotlin/JS Kotlin All The Things
  34. var x = 12345; x = "string"; var x =

    12345; x = "string"; x = { key: "value" }; Dynamically Typed Statically Typed
  35. var HelloJS = function (_, Kotlin) { 'use strict'; var

    println = Kotlin.kotlin.io.println_s8jyv4$; function main(args) { println('Hello JavaScript!'); } _.main_kand9s$ = main; main([]); Kotlin.defineModule('HelloJS', _); return _; }(typeof HelloJS === 'undefined' ? {} : HelloJS, kotlin);
  36. var HelloJS = function (_, Kotlin) { 'use strict'; var

    println = Kotlin.kotlin.io.println_s8jyv4$; function main(args) { println('Hello JavaScript!'); } _.main_kand9s$ = main; main([]); Kotlin.defineModule('HelloJS', _); return _; }(typeof HelloJS === 'undefined' ? {} : HelloJS, kotlin);
  37. var HelloJS = function (_, Kotlin) { 'use strict'; var

    println = Kotlin.kotlin.io.println_s8jyv4$; function main(args) { println('Hello JavaScript!'); } _.main_kand9s$ = main; main([]); Kotlin.defineModule('HelloJS', _); return _; }(typeof HelloJS === 'undefined' ? {} : HelloJS, kotlin); OutputToConsoleLog.prototype.println_s8jyv4$ = function (message) { console.log(message); };
  38. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hello Kotlin/JS</title> </head>

    <body> <script type="text/javascript" src="helloworld.js"></script> </body> </html>
  39. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hello Kotlin/JS</title> </head>

    <body> <script type="text/javascript" src="helloworld.js"></script> </body> </html>
  40. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hello Kotlin/JS</title> </head>

    <body> <script type="text/javascript" src="out/production/HelloJS/lib/kotlin.js"></script> <script type="text/javascript" src="out/production/HelloJS/HelloJS.js"></script> </body> </html>
  41. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hello Kotlin/JS</title> </head>

    <body> <script type="text/javascript" src="out/production/HelloJS/lib/kotlin.js"></script> <script type="text/javascript" src="out/production/HelloJS/HelloJS.js"></script> </body> </html>
  42. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

    Kotlin fun main(args: Array<String>) { js("console.log('Hello World')") }
  43. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

    Kotlin fun main(args: Array<String>) { js("console.log('Hello World')") }
  44. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

    Kotlin external fun alert(message: Any?): Unit fun main(args: Array<String>) { alert("All The Things!") }
  45. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

    Kotlin external fun alert(message: Any?): Unit fun main(args: Array<String>) { alert("All The Things!") }
  46. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

    Kotlin import org.w3c.dom.Window external val window: Window fun main(args: Array<String>) { window.document.location?.href ="https://www.google.com" }
  47. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

    Kotlin https://kotlinlang.org/docs/reference/dynamic-type.html The Dynamic Type val dyn: dynamic = null dyn.foo().bar.baz()
  48. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule fun foo() = "Hello" JavaScript alert(myModule.foo());
  49. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule package my.qualified.packagename fun foo() = "Hello" JavaScript alert(myModule.my.qualified.packagename.foo());
  50. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule class Person(val name: String) { fun hello() = println("Hello $name!") fun hello(greeting: String) = println("$greeting $name!") }
  51. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule class Person(val name: String) { fun hello() = println("Hello $name!") fun hello(greeting: String) = println("$greeting $name!") }
  52. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule class Person(val name: String) { fun hello() = println("Hello $name!") @JsName("helloWithGreeting") fun hello(greeting: String) = println("$greeting $name!") }
  53. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule class Person(val name: String) { fun hello() = println("Hello $name!") @JsName("helloWithGreeting") fun hello(greeting: String) = println("$greeting $name!") } JavaScript var person = new myModule.Person("Dmitry"); myModule.hello(); myModule.helloWithGreeting("Servus");
  54. Kotlin All The Things Kotlin/JS Tooling apply plugin: 'org.jetbrains.kotlin.frontend' kotlinFrontend

    { webpackBundle { bundleName = "main" sourceMapEnabled = true publicPath = "/" host = "localhost" port = 8088 } }
  55. Kotlin All The Things Kotlin/JS + React David Ford -

    Talking Kotlin http://talkingkotlin.com/react-with-kotlin/
  56. Kotlin All The Things Kotlin/JS + React JavaScript class ShoppingList

    extends React.Component { render() { return ( <div className="shopping-list"> <h1>Shopping List for {this.props.name}</h1> <ul> <li>Instagram</li> <li>WhatsApp</li> <li>Oculus</li> </ul> </div> ); } }
  57. Kotlin All The Things Kotlin/JS + React JavaScript class ShoppingList

    extends React.Component { render() { return ( <div className="shopping-list"> <h1>Shopping List for {this.props.name}</h1> <ul> <li>Instagram</li> <li>WhatsApp</li> <li>Oculus</li> </ul> </div> ); } } HTML <ShoppingList name="Mark" />
  58. Kotlin All The Things Kotlin/JS + React JavaScript class ShoppingList

    extends React.Component { render() { return ( <div className="shopping-list"> <h1>Shopping List for {this.props.name}</h1> <ul> <li>Instagram</li> <li>WhatsApp</li> <li>Oculus</li> </ul> </div> ); } }
  59. Kotlin All The Things Kotlin/JS + React Kotlin class ShoppingList

    : ReactDOMComponent<ShoppingList.Props, ShoppingList.State>(){ override fun ReactDOMBuilder.render() { div(classes = "shopping-list") { h1 { +"Shopping List for ${props.name}" } ul{ li{ + "Instagram" } li{ + "WhatsApp" } li{ + "Oculus" } } } } }
  60. Kotlin All The Things Kotlin/JS + React Kotlin class ShoppingList

    : ReactDOMComponent<ShoppingList.Props, ShoppingList.State>(){ override fun ReactDOMBuilder.render() { div(classes = "shopping-list") { h1 { +"Shopping List for ${props.name}" } ul{ li{ + "Instagram" } li{ + "WhatsApp" } li{ + "Oculus" } } } } }
  61. Kotlin All The Things Kotlin/JS + React Create React Kotlin

    App • Scaffold a kotlin react app • Based on the “create-react-app” command • Maintained by JetBrains ◦ https://github.com/JetBrains/create-react-kotlin-app
  62. Kotlin All The Things Kotlin/JS Wrappers https://github.com/JetBrains/kotlin-wrappers • React •

    Redux • Mocca • Styled Components (https://www.styled-components.com) https://github.com/Kotlin/js-externals • jQuery
  63. • Compile Kotlin Code to Native Binaries (non-VM world) •

    LLVM based backend • Supports two-way interoperability ◦ Executable on multiple platforms ◦ Static Library with C headers for C/C++ ◦ Use existing static/dynamic libraries ◦ Supports Objective-C types • Produces executables and libraries/frameworks. Kotlin Native Kotlin All The Things
  64. Supported Platforms • Android (arm32, arm64) • Windows (mingw, x86_64)

    • Linux (x86_64, arm32, MIPSm, MIPS little endian) • WebAssembly (wasm32) • MacOS (x86_64) • iOS (arm32, arm64, emulator x86_64) Kotlin Native Kotlin All The Things
  65. Supported Platforms • Android (arm32, arm64) • Windows (mingw, x86_64)

    • Linux (x86_64, arm32, MIPSm, MIPS little endian) • WebAssembly (wasm32) • MacOS (x86_64) • iOS (arm32, arm64, emulator x86_64) Kotlin Native Kotlin All The Things
  66. Getting Started • Download Intellij and make sure to update

    the Kotlin tooling to 1.3+ Or • Download the compiler: https://github.com/JetBrains/kotlin/releases/tag/v1.3.11 • Extract and add to your path. Kotlin Native Kotlin All The Things
  67. Kotlin Native Kotlin All The Things package sample fun hello():

    String = "Hello, Kotlin/Native!" fun main() { println(hello()) }
  68. Kotlin Native Kotlin All The Things package sample fun hello():

    String = "Hello, Kotlin/Native!" fun main() { println(hello()) } konanc MySample.kt -e sample.main
  69. Kotlin Native Kotlin All The Things package sample fun hello():

    String = "Hello, Kotlin/Native!" fun main() { println(hello()) } konanc MySample.kt -e sample.main
  70. Kotlin Native Kotlin All The Things konanc MySample.kt -e sample.main

    -produce framework -target <ios_x64 | ios_arm64> -output <directory> https://kotlinlang.org/docs/tutorials/native/apple-framework.html
  71. Kotlin Native Kotlin All The Things konanc MySample.kt -e sample.main

    -produce framework -target <ios_x64 | ios_arm64> -output <directory> https://kotlinlang.org/docs/tutorials/native/apple-framework.html
  72. #import <Foundation/Foundation.h> @class DemoKotlinArray; @protocol DemoKotlinIterator; NS_ASSUME_NONNULL_BEGIN @interface KotlinBase :

    NSObject - (instancetype)init __attribute__((unavailable)); + (instancetype)new __attribute__((unavailable)); + (void)initialize __attribute__((objc_requires_super)); @end; ... __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("MySampleKt"))) @interface DemoMySampleKt : KotlinBase + (void)mainArgs:(DemoKotlinArray *)args __attribute__((swift_name("main(args:)"))); @end; ...
  73. #import <Foundation/Foundation.h> @class DemoKotlinArray; @protocol DemoKotlinIterator; NS_ASSUME_NONNULL_BEGIN @interface KotlinBase :

    NSObject - (instancetype)init __attribute__((unavailable)); + (instancetype)new __attribute__((unavailable)); + (void)initialize __attribute__((objc_requires_super)); @end; ... __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("MySampleKt"))) @interface DemoMySampleKt : KotlinBase + (void)mainArgs:(DemoKotlinArray *)args __attribute__((swift_name("main(args:)"))); @end; ...
  74. Kotlin Native Kotlin All The Things https://github.com/JetBrains/kotlin-native/tree/master/samples/opengl fun main() {

    // initialize and run program memScoped { ... } // Display Mode glutInitDisplayMode((GLUT_RGB or GLUT_DOUBLE or GLUT_DEPTH).convert()) // Set window size glutInitWindowSize(windowWidth, windowHeight) // create Window glutCreateWindow("The GLUT Teapot") initialize() // run GLUT mainloop glutMainLoop() }
  75. Kotlin Native Kotlin All The Things https://github.com/JetBrains/kotlin-native/tree/master/samples/opengl fun main() {

    // initialize and run program memScoped { ... } // Display Mode glutInitDisplayMode((GLUT_RGB or GLUT_DOUBLE or GLUT_DEPTH).convert()) // Set window size glutInitWindowSize(windowWidth, windowHeight) // create Window glutCreateWindow("The GLUT Teapot") initialize() // run GLUT mainloop glutMainLoop() }
  76. Kotlin Native Kotlin All The Things https://github.com/JetBrains/kotlin-native/tree/master/samples/opengl fun initialize() {

    // select projection matrix glMatrixMode(GL_PROJECTION) // set the viewport glViewport(0, 0, windowWidth, windowHeight) // set matrix mode glMatrixMode(GL_PROJECTION) // reset projection matrix glLoadIdentity() val aspect = windowWidth.toDouble() / windowHeight // set up a perspective projection matrix gluPerspective(45.0, aspect, 1.0, 500.0) // specify which matrix is the current matrix glMatrixMode(GL_MODELVIEW) glShadeModel(GL_SMOOTH) ... }
  77. Kotlin Native Kotlin All The Things https://github.com/JetBrains/kotlin-native/tree/master/samples/opengl fun initialize() {

    // select projection matrix glMatrixMode(GL_PROJECTION) // set the viewport glViewport(0, 0, windowWidth, windowHeight) // set matrix mode glMatrixMode(GL_PROJECTION) // reset projection matrix glLoadIdentity() val aspect = windowWidth.toDouble() / windowHeight // set up a perspective projection matrix gluPerspective(45.0, aspect, 1.0, 500.0) // specify which matrix is the current matrix glMatrixMode(GL_MODELVIEW) glShadeModel(GL_SMOOTH) ... }
  78. • Set of tools to help share app data/domain code

    natively across platforms ◦ Gradle Plugin ◦ Compile for multiple “targets” ◦ Common + Platform specific code ▪ Expect in common code, Actual in platform code. • Still experimental • It’s not meant to share all code Kotlin Multiplatform Kotlin All The Things
  79. • Data Models • Validation Rules • Network Client Code

    • HTML Generation What to share? Kotlin All The Things
  80. • Rx anything • Threading • Database • UI What

    not to share? Kotlin All The Things
  81. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { jvm()

    js() { compilations.all { kotlinOptions { moduleKind = "umd" } } } android("android") iosX64("ios") { compilations.main.outputKinds("framework") } sourceSets { ... } }
  82. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { ...

    sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } commonTest { dependencies { implementation kotlin('test-common') implementation kotlin('test-annotations-common') } } jvmMain { dependencies {...} } jvmTest { dependencies {...} } jsMain { dependencies {...} } jsTest { dependencies {...} } androidMain { dependencies {...} } androidTest { dependencies {...} } iosMain {} iosTest {} } }
  83. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { ...

    sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } commonTest { dependencies { implementation kotlin('test-common') implementation kotlin('test-annotations-common') } } jvmMain { dependencies {...} } jvmTest { dependencies {...} } jsMain { dependencies {...} } jsTest { dependencies {...} } androidMain { dependencies {...} } androidTest { dependencies {...} } iosMain {} iosTest {} } }
  84. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { ...

    sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } commonTest { dependencies { implementation kotlin('test-common') implementation kotlin('test-annotations-common') } } jvmMain { dependencies {...} } jvmTest { dependencies {...} } jsMain { dependencies {...} } jsTest { dependencies {...} } androidMain { dependencies {...} } androidTest { dependencies {...} } iosMain {} iosTest {} } }
  85. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { ...

    sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } commonTest { dependencies { implementation kotlin('test-common') implementation kotlin('test-annotations-common') } } jvmMain { dependencies {...} } jvmTest { dependencies {...} } jsMain { dependencies {...} } jsTest { dependencies {...} } androidMain { dependencies {...} } androidTest { dependencies {...} } iosMain {} iosTest {} } }
  86. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { ...

    sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } commonTest { dependencies { implementation kotlin('test-common') implementation kotlin('test-annotations-common') } } jvmMain { dependencies {...} } jvmTest { dependencies {...} } jsMain { dependencies {...} } jsTest { dependencies {...} } androidMain { dependencies {...} } androidTest { dependencies {...} } iosMain {} iosTest {} } }
  87. Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html kotlin { ...

    sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } commonTest { dependencies { implementation kotlin('test-common') implementation kotlin('test-annotations-common') } } jvmMain { dependencies {...} } jvmTest { dependencies {...} } jsMain { dependencies {...} } jsTest { dependencies {...} } androidMain { dependencies {...} } androidTest { dependencies {...} } iosMain {} iosTest {} } }
  88. Kotlin Multiplatform Kotlin All The Things https://github.com/JetBrains/kotlin-mpp-example/ > commonMain expect

    class Platform() { val platform: String } class Greeting { fun greeting(): String = "Hello, ${Platform().platform}" }
  89. Kotlin Multiplatform Kotlin All The Things https://github.com/JetBrains/kotlin-mpp-example/ > iosMain actual

    class Platform actual constructor() { actual val platform: String = "iOS" } > androidMain actual class Platform actual constructor() { actual val platform: String = "Android" }
  90. Kotlin Multiplatform Kotlin All The Things https://github.com/JetBrains/kotlin-mpp-example/ > commonMain expect

    class Date > jvmMain actual typealias Date = java.util.Date > jsMain actual typealias Date = kotlin.js.Date
  91. Kotlin Multiplatform Kotlin All The Things https://github.com/JetBrains/kotlin-mpp-example/ > commonMain expect

    class Date > jvmMain actual typealias Date = java.util.Date > jsMain actual typealias Date = kotlin.js.Date
  92. Why Expect/Actual vs Interface? Kotlin All The Things GOTO 2017

    • Kotlin - One Language, All Tiers: Developing Multiplatform Projects • Dmitry Jemerov • Much more flexible • You can “expect” top level functions and extension functions, too. • Allows you to reuse existing implementation if needed.
  93. • Kotlin is a modern, pragmatic, industry built language with

    a great community. • Kotlin became popular on the JVM, but that’s not the only platform for the language. • Multiplatform projects enable us to use Kotlin natively everywhere.
  94. • Docs https://kotlinlang.org/ • Talking Kotlin http://talkingkotlin.com/ • Kotlin Slack

    http://slack.kotlinlang.org/ • Github https://www.github.com/myotive/kotlin-all-the-things • Slides https://speakerdeck.com/myotive/kotlin-all-the-things