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

Kotlin Multiplatform in Action

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
Avatar for Marko Mitic Marko Mitic
September 28, 2019

Kotlin Multiplatform in Action

Kotlin Multiplatform - what it is, why you should use it and how to start with it.

Avatar for Marko Mitic

Marko Mitic

September 28, 2019

Other Decks in Programming

Transcript

  1. Why share code? • DRY • same code/logic for different

    platforms • productivity, features, less bugs, more platforms
  2. Why share code? • crossplatform in the past • networking

    library in C • Windows Mobile • Windows • Android • Linux
  3. Why share code? • sharing entire components • JVM servers

    can share business logic with Android apps • All client apps share similar logic and features
  4. Why NOT share code? • Performance • Slower innovation •

    shared UI • All or nothing • Vendor lock-in • Future • Bugs/lack of features
  5. Why use Kotlin Multiplatform? • modern, industrial language • similar

    to swift, easy for java devs to learn • great tooling, ecosystem and community • open-source • write once, run native everywhere
  6. Why use Kotlin Multiplatform? • doesn’t limit you to subset

    of all platforms • native access to entire platform API from Kotlin • each platform get native, optimized binary • fix bug once, for all platforms • interoperability • optional sharing
  7. Why not other solutions? • Flutter, React Native, Xamarin •

    not same usecase • sharing UI - risky • new language, new tools, new libs • accessing platform APIs is hard, bridges • frameworks
  8. Why not other solutions? “Anything that requires you to make

    large decisions and potentially large rewrites, perform large retrainings and rehirings, or anything that has to share UI or doesn’t work well with a native platform is, well, very risky.” - Kevin Galligan, Touchlab
  9. Kotlin/Native • iOS, Linux, Windows, MacOS, WebAssembly... • build full

    apps or libs • access to native platform APIs • interoperable with C/ObjC(/Swift) • Kotlin can call C/ObjC/Swift and vice-versa • Kotlin can extend ObjC/Swift classes and vice-versa
  10. Concurrency is hard • languages/runtimes allow unsafe concurrency • tools

    - locks & volatile • no warnings • deadlocks • entire burden on devs • no guaranties of safety • bugs leak into production
  11. Saner concurrency • new, stricter memory model • ARC with

    cycle collector • 2 simple rules • Immutable state can be shared among threads • Mutable data belongs to one thread • compiler and runtime check the rules • thread-safe code
  12. Saner concurrency +GC per thread, no suspends +shared reference counter

    with swift -no global mutable state -new concepts, patterns, practices -coroutines
  13. Saner concurrency • Any.freeze() • passing mutable data by detaching

    • No manual concurrency management • Workers • Atomics - AtomicRef/Int/Long/... • “Stranger threads” (link in resources)
  14. Saner concurrency • work in progress • multithreaded coroutines •

    similar rules for JVM • relaxed memory model
  15. Status • beta but relatively stable • low-risk • production

    • large projects - wait for release • smaller projects - maybe • part of a project - yesterday