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

Kotlin All The Things - 2020 edition

Kotlin All The Things - 2020 edition

Michael Yotive

August 20, 2020
Tweet

More Decks by Michael Yotive

Other Decks in Programming

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 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
  7. Sample Kotlin All The Things @SpringBootApplication class DemoApplication fun main(args:

    Array<String>) { runApplication<DemoApplication>(*args) } @RestController class HelloWorldController{ @GetMapping("/") fun helloWorld() = "Hello World!" }
  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 data class SimpleObject(val data:String =

    "Sample") @RestController class HelloWorldController{ @GetMapping("/Sample") fun sample() = (1 .. 10).map { SimpleObject() } }
  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. 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/
  16. KTor Kotlin All The Things const val defaultPort = 8080

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

    fun main() { embeddedServer(Netty, defaultPort, module = Application::main) .start(wait = true) }
  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 fun Application.main(){ install(DefaultHeaders){ header("Access-Control-Allow-Origin", "*")

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

    } install(ContentNegotiation) { gson { setDateFormat(DateFormat.LONG) setPrettyPrinting() } } installRoutes() }
  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.installRoutes() { routing {

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

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

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

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

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

    call.parameters["id"] val data:Session = SessionDB.sessionRepository.find(Session::id eq sessionId) .firstOrDefault() call.respond(data) }
  28. 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) }
  29. KTor Kotlin All The Things data class HelloWorld(val hello: String)

    post("/route") { val helloWorld = call.receive<HelloWorld>() }
  30. var x = 12345; x = "string"; var x =

    12345; x = "string"; x = { key: "value" }; Dynamically Typed Statically Typed
  31. • 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
  32. 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
  33. 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);
  34. 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);
  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); OutputToConsoleLog.prototype.println_s8jyv4$ = function (message) { console.log(message); };
  36. <!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>
  37. <!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>
  38. <!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>
  39. <!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>
  40. Calling JavaScript from Kotlin Kotlin All The Things Javascript ⬌

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

    Kotlin fun main(args: Array<String>) { js("console.log('Hello World')") }
  42. 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!") }
  43. 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!") }
  44. 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" }
  45. 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()
  46. Calling Kotlin from JavaScript Kotlin All The Things Javascript ⬌

    Kotlin Kotlin Module: myModule fun foo() = "Hello" JavaScript alert(myModule.foo());
  47. 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());
  48. 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!") }
  49. 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!") }
  50. 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!") }
  51. 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");
  52. Kotlin All The Things JavaScript Modules compileKotlin2Js.kotlinOptions.moduleKind = ‘<module kind>’

    • Plain • AMD - used by Require.js • CommonJS - used by Node.js/NPM • UMD - supports both AMD and CommonJS
  53. Kotlin All The Things Kotlin/JS Tooling apply plugin: 'org.jetbrains.kotlin.js' kotlin

    { target { nodejs() } sourceSets["main"].dependencies { implementation(kotlin("stdlib-js")) implementation(npm("react", "16.8.3")) } }
  54. Kotlin All The Things Kotlin/JS + React David Ford -

    Talking Kotlin http://talkingkotlin.com/react-with-kotlin/
  55. 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> ); } }
  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> ); } } HTML <ShoppingList name="Mark" />
  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> ); } }
  58. 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" } } } } }
  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 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
  61. 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
  62. • 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
  63. 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
  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. 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.70 • Extract and add to your path. Kotlin Native Kotlin All The Things
  66. Kotlin Native Kotlin All The Things package sample fun hello():

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

    String = "Hello, Kotlin/Native!" fun main() { println(hello()) } konanc MySample.kt -e sample.main
  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 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() }
  70. 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() }
  71. 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) ... }
  72. 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) ... }
  73. 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
  74. 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
  75. #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; ...
  76. #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; ...
  77. • 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
  78. • Data Models • Validation Rules • Network Client Code

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

    not to share? Kotlin All The Things
  80. 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 { ... } }
  81. 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 {} } }
  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://github.com/JetBrains/kotlin-mpp-example/ > commonMain expect

    class Platform() { val platform: String } class Greeting { fun greeting(): String = "Hello, ${Platform().platform}" }
  88. 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" }
  89. 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
  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. 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.
  92. Who is using KMP in Production? Kotlin All The Things

    https://tech.target.com/2019/04/02/gift-registry-kotlin-multiplatform.html
  93. Who is using KMP in Production? Kotlin All The Things

    https://developer.squareup.com/blog/developing-on-ios-and-android/
  94. Misc “Things” Kotlin All The Things • KScript ◦ The

    State of KScript https://medium.com/@mbonnin/may-2020-the-state-of-kotlin-scripting-99cb6cc57db1 ◦ Clikt https://ajalt.github.io/clikt/ • Kotlin Gradle DSL
  95. • 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.
  96. • 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