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

Sharing [Kotlin code across platforms] is caring!

Sharing [Kotlin code across platforms] is caring!

Sharing code across platforms is one of the most annoying "unsolved problems" when developing a product: an eternal struggle between re-writing everything multiple times and jumping through plenty of hoops to be able to re-use some core business logic. This session is going to illustrate how Kotlin is being used to solve this problem at Clue in order to share code between Android, iOS and the backend, including all the challenges, lessons and tricks learned along the way.

Presented at KotlinConf 2017

Eugenio Marletti

November 03, 2017
Tweet

More Decks by Eugenio Marletti

Other Decks in Technology

Transcript

  1. C++ ObjC++ JavaScript TypeScript iOS !" JavaScriptCore Android !" W

    ͊̊̏̃͑̽̃̕ ̘͖̯ 㸅 ̨͇̯ ̶ȩ̧̟̝͔ ͔͎̗̬̼̓̒̄̍̓͐̒̎̕ b̡̫̰͙͚͋͋̓́̇͟V ͐̇͞ ̓̿̔̿̓ ͒̚ ͟ ̨̭̳̱͕ ̵i ͒̅̉͊̌̇ ̡͓̰̲̳͟ ̥̯ ̯̦ę͕͔͉̜̗͔͎ ̔̍̀̏̌̕ ͢ ͟ w ̛͊͆̍͑ ̴̯̯̻̪̦
  2. class Value { constructor(value: Double) { this.value = value }

    val value: Double override fun toString(): String { return this.value.toString() } companion object { fun add(v1: Value, v2: Value): Value { return Value(v1.value + v2.value) } fun isZero(valueWithVariance: Value): Boolean { return .0 !!% valueWithVariance.value } fun subtract(v1: Value?, v2: Value?): Value { var value = .0 if (v1 !' null !& v2 !' null) { value = v1.value - v2.value } return Value(value) } } } export class Value { constructor(value) { this.value = value } readonly value: number toString() { return String(this.value) } static add = (v1: Value, v2: Value): Value !$ { return new Value(v1.value + v2.value) } static isZero = (valueWithVariance: Value): boolean !$ { return 0 !!% valueWithVariance.value } static subtract = (v1: Value, v2: Value): Value !$ { let value = 0 if (v1 !& v2) { value = v1.value - v2.value } return new Value(value) } }