Slide 1

Slide 1 text

Kotlin All The Things Michael Yotive @myotive Big Nerd Ranch

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Who am I?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Why All The Things? Kotlin All The Things ● Save time/money ○ Caution: Big investment ● Sharing code within/across company ● Increased Quality ● Feature teams

Slide 11

Slide 11 text

● Kotlin on the Server ● Client Side Kotlin ● Kotlin/Native ● Kotlin Multiplatform Kotlin All The Things Agenda

Slide 12

Slide 12 text

Kotlin on the Server (JVM)

Slide 13

Slide 13 text

Kotlin on the Server Backend ● Read dynamic data ● Authenticate ● Write/Persist data Kotlin All The Things

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Kotlin on the Server Kotlin All The Things KotlinConf 2018 - Komparing Kotlin Server Frameworks by Ken Yee https://www.youtube.com/watch?v=8xfQA10Cd7g

Slide 16

Slide 16 text

Spring and Spring Boot Kotlin All The Things

Slide 17

Slide 17 text

Spring and Spring Boot Kotlin All The Things

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Spring and Spring Boot Kotlin All The Things

Slide 20

Slide 20 text

SpringInitializr Kotlin All The Things https://start.spring.io

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

KTor Kotlin All The Things https://ktor.io/

Slide 30

Slide 30 text

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/

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

KTor Kotlin All The Things fun Application.installRoutes() { routing { get("/") { ... } get("/sessions") { ... } get("/sessions/{id}") { ... } } }

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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) }

Slide 43

Slide 43 text

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) }

Slide 44

Slide 44 text

KTor Kotlin All The Things data class HelloWorld(val hello: String) post("/route") { val helloWorld = call.receive() }

Slide 45

Slide 45 text

KTor Kotlin All The Things

Slide 46

Slide 46 text

Client Side Kotlin (Kotlin/JS)

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

https://insights.stackoverflow.com/survey/2020/

Slide 49

Slide 49 text

https://insights.stackoverflow.com/survey/2019/

Slide 50

Slide 50 text

https://insights.stackoverflow.com/survey/2018/

Slide 51

Slide 51 text

https://insights.stackoverflow.com/survey/2020/

Slide 52

Slide 52 text

https://insights.stackoverflow.com/survey/2020/

Slide 53

Slide 53 text

https://insights.stackoverflow.com/survey/2019/ !!!!

Slide 54

Slide 54 text

https://insights.stackoverflow.com/survey/2018/ !!!!

Slide 55

Slide 55 text

var x = 12345; x = "string"; var x = 12345; x = "string"; x = { key: "value" }; Dynamically Typed Statically Typed

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

● 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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

fun main(args: Array) { println("Hello JavaScript!") } kotlinc-js helloworld.kt -output helloworld.js File: helloworld.kt

Slide 60

Slide 60 text

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);

Slide 61

Slide 61 text

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);

Slide 62

Slide 62 text

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); };

Slide 63

Slide 63 text

Hello Kotlin/JS

Slide 64

Slide 64 text

Hello Kotlin/JS

Slide 65

Slide 65 text

fun main(args: Array) { println("Hello JavaScript!") } kotlinc-js Module: HelloJS File: main.kt

Slide 66

Slide 66 text

Hello Kotlin/JS

Slide 67

Slide 67 text

Hello Kotlin/JS

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

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()

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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());

Slide 76

Slide 76 text

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!") }

Slide 77

Slide 77 text

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!") }

Slide 78

Slide 78 text

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!") }

Slide 79

Slide 79 text

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");

Slide 80

Slide 80 text

Kotlin All The Things JavaScript Modules compileKotlin2Js.kotlinOptions.moduleKind = ‘’ ● Plain ● AMD - used by Require.js ● CommonJS - used by Node.js/NPM ● UMD - supports both AMD and CommonJS

Slide 81

Slide 81 text

Kotlin All The Things Kotlin/JS Tooling apply plugin: 'org.jetbrains.kotlin.js'

Slide 82

Slide 82 text

Kotlin All The Things Kotlin/JS Tooling apply plugin: 'org.jetbrains.kotlin.js' kotlin { target { nodejs() browser() } }

Slide 83

Slide 83 text

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")) } }

Slide 84

Slide 84 text

Kotlin All The Things Kotlin/JS + React David Ford - Talking Kotlin http://talkingkotlin.com/react-with-kotlin/

Slide 85

Slide 85 text

Kotlin All The Things Kotlin/JS + React JavaScript class ShoppingList extends React.Component { render() { return (

Shopping List for {this.props.name}

  • Instagram
  • WhatsApp
  • Oculus
); } }

Slide 86

Slide 86 text

Kotlin All The Things Kotlin/JS + React JavaScript class ShoppingList extends React.Component { render() { return (

Shopping List for {this.props.name}

  • Instagram
  • WhatsApp
  • Oculus
); } } HTML

Slide 87

Slide 87 text

Kotlin All The Things Kotlin/JS + React JavaScript class ShoppingList extends React.Component { render() { return (

Shopping List for {this.props.name}

  • Instagram
  • WhatsApp
  • Oculus
); } }

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

Kotlin/Native

Slide 93

Slide 93 text

● 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

Slide 94

Slide 94 text

Kotlin Native Kotlin All The Things Source KONANC LLVM Native Binary LLVM IR Front End Back End

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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

Slide 101

Slide 101 text

Kotlin Native Kotlin All The Things https://kotlinlang.org/docs/reference/native/platform_libs.html import platform.GLUT.* import platform.OpenGL.* import platform.OpenGLCommon.*

Slide 102

Slide 102 text

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() }

Slide 103

Slide 103 text

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() }

Slide 104

Slide 104 text

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) ... }

Slide 105

Slide 105 text

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) ... }

Slide 106

Slide 106 text

Kotlin Native Kotlin All The Things konanc MySample.kt -e sample.main -produce framework -target -output https://kotlinlang.org/docs/tutorials/native/apple-framework.html

Slide 107

Slide 107 text

Kotlin Native Kotlin All The Things konanc MySample.kt -e sample.main -produce framework -target -output https://kotlinlang.org/docs/tutorials/native/apple-framework.html

Slide 108

Slide 108 text

#import @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; ...

Slide 109

Slide 109 text

#import @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; ...

Slide 110

Slide 110 text

Kotlin Multiplatform

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

● 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

Slide 114

Slide 114 text

● Data Models ● Validation Rules ● Network Client Code ● HTML Generation What to share? Kotlin All The Things

Slide 115

Slide 115 text

● UI ● Rx anything ● Threading ● Database? What not to share? Kotlin All The Things

Slide 116

Slide 116 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 117

Slide 117 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 118

Slide 118 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 119

Slide 119 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 120

Slide 120 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html plugins { id 'kotlin-multiplatform' version '1.3.72' }

Slide 121

Slide 121 text

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 { ... } }

Slide 122

Slide 122 text

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 {} } }

Slide 123

Slide 123 text

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 {} } }

Slide 124

Slide 124 text

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 {} } }

Slide 125

Slide 125 text

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 {} } }

Slide 126

Slide 126 text

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 {} } }

Slide 127

Slide 127 text

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 {} } }

Slide 128

Slide 128 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 129

Slide 129 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 130

Slide 130 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 131

Slide 131 text

Kotlin Multiplatform Kotlin All The Things https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html

Slide 132

Slide 132 text

Kotlin Multiplatform Kotlin All The Things https://github.com/JetBrains/kotlin-mpp-example/ class Calculator { companion object { fun sum(a: Int, b: Int): Int = a + b } }

Slide 133

Slide 133 text

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

Slide 134

Slide 134 text

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

Slide 135

Slide 135 text

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}" }

Slide 136

Slide 136 text

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" }

Slide 137

Slide 137 text

Kotlin Multiplatform Kotlin All The Things https://github.com/JetBrains/kotlin-mpp-example/

Slide 138

Slide 138 text

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

Slide 139

Slide 139 text

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

Slide 140

Slide 140 text

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.

Slide 141

Slide 141 text

Kotlin Multiplatform In Production

Slide 142

Slide 142 text

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

Slide 143

Slide 143 text

Who is using KMP in Production? Kotlin All The Things https://developer.squareup.com/blog/developing-on-ios-and-android/

Slide 144

Slide 144 text

Who is using KMP in Production? Kotlin All The Things

Slide 145

Slide 145 text

Who is using KMP in Production? Kotlin All The Things

Slide 146

Slide 146 text

Who is using KMP in Production? Kotlin All The Things https://touchlab.co/

Slide 147

Slide 147 text

Misc

Slide 148

Slide 148 text

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

Slide 149

Slide 149 text

Conclusion

Slide 150

Slide 150 text

● 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.

Slide 151

Slide 151 text

● 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

Slide 152

Slide 152 text

Thank you! Let’s Build Brilliance www.bignerdranch.com 200 Arizona Ave NE, Suite 200, Atlanta, GA 30307 [email protected] @myotive