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

10 Reasons To Try Kotlin Multiplatform [GOTO Copenhagen edition]

pahill
October 09, 2023

10 Reasons To Try Kotlin Multiplatform [GOTO Copenhagen edition]

Is multiplatform development a realistic proposition? What should drive you to choose Kotlin Multiplatform over the alternatives? In this talk, I’ll take a close look at the Kotlin Multiplatform technology and ecosystem and offer ten compelling reasons why you should give it a go!

Those in the know will surely be aware that the Kotlin ecosystem has been transforming. Thanks to new compilers, libraries, and frameworks, Kotlin has become a multiplatform environment. You can develop compelling apps on the desktop, iOS, Android, and even WebAssembly – all from a single codebase. As such, Kotlin Multiplatform is now in direct competition with technologies like Flutter and React Native.

pahill

October 09, 2023
Tweet

More Decks by pahill

Other Decks in Programming

Transcript

  1. What kind of platforms? Server Android iOS Desktop Web Kotlin

    Multiplatform WASM JS #2: Extensive list of supported platforms
  2. What is WASM? • WebAssembly (WASM) is a binary instruction

    format for portable virtual machines • Smaller, faster than JavaScript • Don’t write code in WASM, but languages like Kotlin / Go / Rust, compile to WASM • Already supported in most modern browsers, Node.js #2: Extensive list of supported platforms
  3. Settled on Kotlin Multiplatform 🏆 Android iOS Web Kotlin Multiplatform

    https://kotlinlang.org/lp/multiplatform/case-studies/quizlet/ #2: Extensive list of supported platforms
  4. The results 🏆 ✅ Type-safe APIs when marshalling objects ✅

    Performance on Android/iOS improved ✅ Android app size decreased ✅ Better developer experience ✅ Different team members keen to try writing shared code #2: Extensive list of supported platforms
  5. Before: Sharing data models Use a language-neutral, platform-neutral language like

    Protocol Buffers ✅ Use with any language - like Go 🚫 Need to learn yet another format 🚫 Need to generate data classes from .proto files on all platforms #2: Extensive list of supported platforms
  6. Sharing data models with Kotlin Multiplatform 🏆 ✅ Use a

    familiar language with great tooling ✅ Write once, use everywhere ❓Does it work with all your languages (server-side: only JVM) #2: Extensive list of supported platforms
  7. 3. Supportive community 1. Already used by big companies 2.

    Extensive list of supported platforms
  8. Kotlinlang Slack Workspace • 56k+ members • Relevant channels: ◦

    #multiplatform ◦ #compose-ios • Q&A with JetBrains/Google/other knowledgeable experts #3: Supportive community
  9. Google @Google Touchlab @TouchlabHQ Philipp Lackner @plcoding John O’Reilly @joreilly

    Sebastian Aigner @sebi_io Garth Gilmour @GarthGilmour Lena Stepanova @hlnstep Tadeas Kriz @TadeasKriz #3: Supportive community
  10. The problem with native app dev https://kotlinlang.org/lp/multiplatform/case-studies/baidu • Inconsistencies in

    the app experience • High cost of verifying the business logic • High upgrade and maintenance costs #4: Avoid duplication
  11. “The complex and inconsistent business logic of the iOS and

    Android platforms led to increasing maintenance costs for the app.” - Baidu #4: Avoid duplication
  12. Unifying data layer https://kotlinlang.org/lp/multiplatform/case-studies/baidu • Data model • RESTful API

    requests • JSON data parsing • Caching logic #4: Avoid duplication
  13. The results 🏆 ✅ Consistent experience ✅ Reduced cost of

    maintenance ✅ Reduced cost of testing ✅ Improved productivity https://kotlinlang.org/lp/multiplatform/case-studies/baidu #4: Avoid duplication
  14. Start small • Constants • Migrate common utilities • Write

    or migrate business logic #6: Start sharing gradually
  15. 7. Choose what to share, what to write natively 5.

    Use in new or existing projects 6. Start sharing gradually
  16. Before Kotlin Multiplatform Business / Domain (Entities, Use Cases, Interactors)

    Data / Core (Repositories, HTTP Clients, Cache) UI (Views) Presentation (Presenters, View Models, Controllers) iOS Business / Domain (Entities, Use Cases, Interactors) Data / Core (Repositories, HTTP Clients, Cache) UI (Views) Presentation (Presenters, View Models, Controllers) Android Business / Domain (Entities, Use Cases, Interactors) Data / Core (Repositories, HTTP Clients, Cache) UI (Views) Presentation (Presenters, View Models, Controllers) Desktop #7: Choose what to share, what to write natively
  17. Sharing Business Logic Business / Domain (Entities, Use Cases, Interactors)

    Data / Core (Repositories, HTTP Clients, Cache) UI (Views) Presentation (Presenters, View Models, Controllers) iOS Kotlin Multiplatform Shared Module UI (Views) Presentation (Presenters, View Models, Controllers) Android UI (Views) Presentation (Presenters, View Models, Controllers) Desktop #7: Choose what to share, what to write natively
  18. Sharing UI Logic Business / Domain (Entities, Use Cases, Interactors)

    Data / Core (Repositories, HTTP Clients, Cache) UI (Views) iOS Kotlin Multiplatform Shared Module UI (Views) Android UI (Views) Presentation (Presenters, View Models, Controllers) Desktop #7: Choose what to share, what to write natively
  19. With ✨ Compose Multiplatform✨ Business / Domain (Entities, Use Cases,

    Interactors) Data / Core (Repositories, HTTP Clients, Cache) iOS Kotlin Multiplatform Shared Module UI (Views) Android Presentation (Presenters, View Models, Controllers) Desktop Platform-specific code Platform-specific code Platform-specific code #7: Choose what to share, what to write natively
  20. 8. Share UI code 5. Use in new or existing

    projects 6. Choose what to share, what to write natively
  21. What did we see? ✅ Lots of code sharing between

    Android and iOS ✅ Using native code from common code ✅ Using common code from platform apps #8: Share UI code
  22. 9. Comparable to native 7. Choose what to share, what

    to write natively 8. Share UI code
  23. Using native dependencies • Support for Apple APIs - out

    of the box • Support for dependencies published as CocoaPods - tiny bit of configuration • Support for dependencies not managed by Dependency Manager - possible ➔ Makes the common easy, and the less common possible. #9: Comparable to native
  24. No reasonable use cases known to be significantly less performant

    than native / other cross-platform #9: Comparable to native
  25. 10. Kotlin is a loved & trusted language for everyone

    🩷 8. Share UI code 9. Comparable to native
  26. What do people say about Kotlin? • Concise • Expressive

    • Original • Sound https://www.youtube.com/watch?v=PsaFVLr8t4E (2018) #10. Because Kotlin
  27. Kotlin aims to be pragmatic • Readability over concision •

    Reuse over expressiveness • Interoperability over originality • Safety & tooling over soundness https://www.youtube.com/watch?v=PsaFVLr8t4E (2018) #10. Because Kotlin
  28. Data Classes data class Person( val firstName: String, val secondName:

    String?, val surname: String ) {} • Getters, setters for each property • equals • hashCode • toString • copy • componentN #10. Because Kotlin
  29. Safely Handle null // Task 0: Print the name (naive)

    println("$firstName $secondName $surname") Adele Blue Adkins Taylor null Swift #10. Because Kotlin
  30. Safely Handle null // Task 1: Print the second name

    in uppercase println("$firstName ${secondName?.uppercase()} $surname") Adele BLUE Adkins Taylor null Swift #10. Because Kotlin
  31. Safely Handle null // Task 2: Println the second name

    in uppercase, if available println("$firstName ${secondName?.uppercase() ?: ""} $surname") Adele BLUE Adkins Taylor Swift #10. Because Kotlin
  32. Handling Equality Better Java // Value/Structural Equality person1.equals(person2) // Referential

    Equality person1 == person2 Kotlin // Value/Structural Equality person1 == person2 // Referential Equality person1 === person2 #10. Because Kotlin
  33. “To == or not to ==, that is the question”

    - Java Hamlet #10. Because Kotlin
  34. Work out an experiment plan 󰟾󰞲 • Hypothesis: what do

    we think will happen? • Method: how will we go about our experiment? • Conclusion: how will we analyse our results?
  35. Work out an experiment plan 󰟾󰞲 • Team roles -

    who will contribute actively? • Workflow - how do you make, distribute changes? • Coding standards - how to write nice APIs • CI/CD - testing and rolling out • Monitoring production
  36. Gain trust, expand the scope • Retrospective - did this

    really work for us? • Yes - do we want to expand the scope? • No - why?
  37. Summary 1. Already used by big companies 2. Extensive list

    of supported platforms 3. Supportive community 4. Avoid duplication 5. Use in new or existing projects
  38. 6. Start sharing gradually 7. Choose what to share, what

    to write natively 8. Share UI code 9. Comparable to native 10. Kotlin is a loved & trusted language for everyone Summary
  39. 1. Start small 2. Work out an experiment plan 3.

    Gain trust, then expand the scope Summary - call to action