SlideShare a Scribd company logo
1 of 44
What
Why
Who
When
Where
How
Why share code?
• DRY
• same code/logic for different platforms
• productivity, features, less bugs, more platforms
Why share code?
• crossplatform in the past
• networking library in C
• Windows Mobile
• Windows
• Android
• Linux
Why share code?
• sharing entire components
• JVM servers can share business logic with Android apps
• All client apps share similar logic and features
Why share code?
• Mobile platforms share a
lot in common
Why NOT share code?
• Performance
• Slower innovation
• shared UI
• All or nothing
• Vendor lock-in
• Future
• Bugs/lack of features
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
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
Why use Kotlin Multiplatform?
optional sharing
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
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
JetBrains
• Coroutines
• Ktor
• kotlinx.serialization
• SQLDelight
• okio
• okhttp?
Touchlab
• Stately
How to start?
• Android Studio
• InteliJ IDEA
Expect/actual
declare expected class/fun/property in common code
actually implement in platform-specific code
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
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
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
Saner concurrency
+GC per thread, no suspends
+shared reference counter with swift
-no global mutable state
-new concepts, patterns, practices
-coroutines
Saner concurrency
• Any.freeze()
• passing mutable data by detaching
• No manual concurrency management
• Workers
• Atomics - AtomicRef/Int/Long/...
• “Stranger threads” (link in resources)
Saner concurrency
• work in progress
• multithreaded coroutines
• similar rules for JVM
• relaxed memory model
Status
• beta but relatively stable
• low-risk
• production
• large projects - wait for release
• smaller projects - maybe
• part of a project - yesterday
resources: cutt.ly/kmp-ns
email: mmitic89@outlook.com
android-serbia slack: @Marko Mitić
kotlinlang slack: @Marko Mitic

More Related Content

What's hot

What's hot (20)

Robot Framework with actual robot
Robot Framework with actual robot Robot Framework with actual robot
Robot Framework with actual robot
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Chapter 1 java
Chapter 1 java Chapter 1 java
Chapter 1 java
 
Azure at the command line
Azure at the command lineAzure at the command line
Azure at the command line
 
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ BrnoJenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
 
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
 
The Beam Vision for Portability: "Write once run anywhere"
The Beam Vision for Portability: "Write once run anywhere"The Beam Vision for Portability: "Write once run anywhere"
The Beam Vision for Portability: "Write once run anywhere"
 
Infinum iOS Talks #2 - Xamarin by Ivan Đikić
Infinum iOS Talks #2 - Xamarin by Ivan ĐikićInfinum iOS Talks #2 - Xamarin by Ivan Đikić
Infinum iOS Talks #2 - Xamarin by Ivan Đikić
 
Building a Language Server for Eclipse MicroProfile
Building a Language Server for Eclipse MicroProfileBuilding a Language Server for Eclipse MicroProfile
Building a Language Server for Eclipse MicroProfile
 
The tools & technologies behind Resin.io
The tools & technologies behind Resin.ioThe tools & technologies behind Resin.io
The tools & technologies behind Resin.io
 
Docker Practical Use Cases
Docker Practical Use CasesDocker Practical Use Cases
Docker Practical Use Cases
 
Landscape of Eclipse MicroProfile Tools
Landscape of Eclipse MicroProfile ToolsLandscape of Eclipse MicroProfile Tools
Landscape of Eclipse MicroProfile Tools
 
Functional solid
Functional solidFunctional solid
Functional solid
 
Functional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakFunctional Solid, Aleksandr Sugak
Functional Solid, Aleksandr Sugak
 
Introduction to Phoenix Web Framework
Introduction to Phoenix Web FrameworkIntroduction to Phoenix Web Framework
Introduction to Phoenix Web Framework
 
CLI, SDK, Doc... What if we generate them?
CLI, SDK, Doc... What if we generate them?CLI, SDK, Doc... What if we generate them?
CLI, SDK, Doc... What if we generate them?
 
Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...
Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...
Javantura v4 - Self-service app deployment with Kubernetes and OpenShift - Ma...
 
Guided overview of software frameworks qt framework
Guided overview of software frameworks   qt frameworkGuided overview of software frameworks   qt framework
Guided overview of software frameworks qt framework
 
Better Swift from the Foundation up #tryswiftnyc17 09-06
Better Swift from the Foundation up #tryswiftnyc17 09-06Better Swift from the Foundation up #tryswiftnyc17 09-06
Better Swift from the Foundation up #tryswiftnyc17 09-06
 

Similar to Kotlin Multiplatfom In Action

NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 

Similar to Kotlin Multiplatfom In Action (20)

Native App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual StudioNative App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual Studio
 
Portable Class Library Deep Dive
Portable Class Library Deep DivePortable Class Library Deep Dive
Portable Class Library Deep Dive
 
Cross Platform Development in C# (DDDNorth 2013)
Cross Platform Development in C# (DDDNorth 2013)Cross Platform Development in C# (DDDNorth 2013)
Cross Platform Development in C# (DDDNorth 2013)
 
C# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform developmentC# everywhere: Xamarin and cross platform development
C# everywhere: Xamarin and cross platform development
 
Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?
 
Building a Cross-Platform Mobile SDK in Rust.pdf
Building a Cross-Platform Mobile SDK in Rust.pdfBuilding a Cross-Platform Mobile SDK in Rust.pdf
Building a Cross-Platform Mobile SDK in Rust.pdf
 
The Architect Way
The Architect WayThe Architect Way
The Architect Way
 
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
 
Why Kotlin?
Why Kotlin?Why Kotlin?
Why Kotlin?
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
Go: What's Different ?
Go: What's Different ?Go: What's Different ?
Go: What's Different ?
 
Starting from scratch in 2017
Starting from scratch in 2017Starting from scratch in 2017
Starting from scratch in 2017
 
Italian Alt.Net Conference MonoTouch Session
Italian Alt.Net Conference MonoTouch SessionItalian Alt.Net Conference MonoTouch Session
Italian Alt.Net Conference MonoTouch Session
 
Introduction to xamarin
Introduction to xamarin  Introduction to xamarin
Introduction to xamarin
 
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
ITB2024 - Keynote Day 1 - Ortus Solutions.pdfITB2024 - Keynote Day 1 - Ortus Solutions.pdf
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
 
Titanium: Native Mobile Apps with Javascript
Titanium: Native Mobile Apps with Javascript Titanium: Native Mobile Apps with Javascript
Titanium: Native Mobile Apps with Javascript
 
Introduction to xamarin
Introduction to xamarinIntroduction to xamarin
Introduction to xamarin
 
Titanium appcelerator kickstart
Titanium appcelerator kickstartTitanium appcelerator kickstart
Titanium appcelerator kickstart
 
Radu vunvulea building and testing windows 8 metro style applications using ...
Radu vunvulea  building and testing windows 8 metro style applications using ...Radu vunvulea  building and testing windows 8 metro style applications using ...
Radu vunvulea building and testing windows 8 metro style applications using ...
 
GWT Jug Stuttgart
GWT Jug StuttgartGWT Jug Stuttgart
GWT Jug Stuttgart
 

Recently uploaded

Recently uploaded (20)

WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 

Kotlin Multiplatfom In Action

  • 1.
  • 2.
  • 4.
  • 5.
  • 6.
  • 7. Why share code? • DRY • same code/logic for different platforms • productivity, features, less bugs, more platforms
  • 8. Why share code? • crossplatform in the past • networking library in C • Windows Mobile • Windows • Android • Linux
  • 9. Why share code? • sharing entire components • JVM servers can share business logic with Android apps • All client apps share similar logic and features
  • 10.
  • 11. Why share code? • Mobile platforms share a lot in common
  • 12. Why NOT share code? • Performance • Slower innovation • shared UI • All or nothing • Vendor lock-in • Future • Bugs/lack of features
  • 13. 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
  • 14. 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
  • 15. Why use Kotlin Multiplatform? optional sharing
  • 16. 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
  • 17.
  • 18. 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
  • 19.
  • 20. JetBrains • Coroutines • Ktor • kotlinx.serialization
  • 21. • SQLDelight • okio • okhttp? Touchlab • Stately
  • 22.
  • 23. How to start? • Android Studio • InteliJ IDEA
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Expect/actual declare expected class/fun/property in common code actually implement in platform-specific code
  • 32.
  • 33.
  • 34.
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. Saner concurrency +GC per thread, no suspends +shared reference counter with swift -no global mutable state -new concepts, patterns, practices -coroutines
  • 39. Saner concurrency • Any.freeze() • passing mutable data by detaching • No manual concurrency management • Workers • Atomics - AtomicRef/Int/Long/... • “Stranger threads” (link in resources)
  • 40. Saner concurrency • work in progress • multithreaded coroutines • similar rules for JVM • relaxed memory model
  • 41.
  • 42. Status • beta but relatively stable • low-risk • production • large projects - wait for release • smaller projects - maybe • part of a project - yesterday
  • 43.
  • 44. resources: cutt.ly/kmp-ns email: mmitic89@outlook.com android-serbia slack: @Marko Mitić kotlinlang slack: @Marko Mitic

Editor's Notes

  1. What is Kotlin mutliplatform? One of the goals for Kotlin is being able to compile to and run on all platforms. 3 compiler backends - Kotlin/JVM, Kotlin/JS, Kotlin/Native - This, together with tools that facilitate efficient code sharing and projects targeting multiple platforms - KMP We'll talk more about multiplatform, but first - WHY
  2. DRY principle, avoid code duplication no need to write same code/logic for different platforms better productivity, more features, less bugs, reach more platforms
  3. Crossplatform in native world IKEv2 lib - windows & windows mobile, android, Linux With rise of VMs and new languages, no common code could serve all platforms
  4. Given proper architecture, sharing entire components can be relatively easy JVM servers can share business logic with Android apps All client apps share similar logic and features
  5. Spotify client apps - while frontend/UI differs from platform to platform features and logic behind are mostly identical it's easy to see how sharing code across platforms can be really benefitial for various usecases
  6. Mobile platforms share a lot in common Android & IOS apps tend to look similar, share identical features, same usacases, platforms have same capabilities and similar limitation app arhitectures are very similar if youre using some layered arhitecture like Clean arhitecure, your app might look like this Domain layer (business logic) is usually great candidate for sharing as it doesn't depend on frameworks and platform Data layer - works with identical data across platforms
  7. performance tend to suffer,VM, interpreters, script languages inovation slows down as advancements on one platform cant be used in shared solutions UI is limited to shared features, not as good as native enitire app must be written in given framework changing framework requires entire app rewrite will that framework even exist in 5-10 years? if we run into an issue or framework lacks needed feature, project goes back to starting point
  8. modern, industrial language similar to swift, easy for java devs to learn top tooling, great ecosystem and community write once, run native everywhere
  9. 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
  10. pick what you want to share, no need to decide on porting entire app pick easily shareable compoment, give it a try even if you don't want to continue using it, you have perfectly fine Android code low risk easy to adopt - easy to convince management - they care about risk
  11. sharing UI - risky - doesn't feel like native Flutter/ReactNative App using Flutter is Flutter app, app using RN is RN app, app using KMP is just an app - you can add KMP library/module without affecting app structure/framework. You can add two, three. You can add KMP lib to Flutter or RN app. - new language, new tools, new libs - issues are localized in KMP - framework vs library
  12. optional sharing - pick your adventure
  13. who's using or supporting KMP
  14. coroutines - great asynchronous programing ktor - Ktor is a framework for building asynchronous servers and clients you can build web servers with it and it also offers multiplatform network client you can use in your applications with ktor, you can write all your networking code once in common code and use that on all platforms serialization - offers reflection-less serialization of kotlin classes to JSON and binary formats uses a compiler plugin to generate code needed for serialization supports all platform - common code
  15. SQLDelight - DB library. SQLDelight generates typesafe APIs from your SQL statements. It compile-time verifies your schema, statements, and migrations and provides IDE features like autocomplete and refactoring which make writing and maintaining SQL simple. Multiplatform library, write all your DB code once in common code and use on all platforms okio - modern I/O library, okhttp okhttp - esential HTTP library for andoird devs, some people may know it as retrofit, which builds upon it. Rewriten in Kotlin, we might get multiplatform release in the future Touchlab - active in K/N developement, stately - concurrency in K/N,
  16. IDEA community edition - free Ultimate edition new project templates KMP templates - clone/fork from github write build script yourself
  17. target - target is a part of the build that is responsible for building, testing, and packaging a complete piece of software for one of the platforms
  18. current state of dependencies what if we wanted to add a server to the picture?
  19. we can improve - Android & iOS are both clients are we'll probably need some client-specific code that we wont need on server - clients sourceSet Android & server both run on JVM - maybe we can put some common dependencies and utilities in jvm sourceSet
  20. we added jvm target, with “server”sourceSet
  21. -> concurrency
  22. Traditionally languages allow (and promote) inherently unsafe concurrency Straighforward code is thread-unsafe by default Languages/runtime offer tools for handling concurrency However these tools haven't changed much since time of C - volatile & locks (synchronized) Languages do nothing to prevent or warn about issues, they are hard to detect Developers must find potential issues and implement safety themselves using given tools Overuse of misuse of concurrency tools lead to deadlocks Entire burden on devs There is no practically no guaranties of thread-safe code, testing just can’t reproduce some concurrency bugs and debugging doesn't help much Often these bugs leak into production In order to address this issue, Kotlin creators indroduced Saner concurrency
  23. Automatic Reference Counting
  24. freeze converts mutable state into immutable state, also all it's references, recursively Data can be manually detached from thread and passed to another one (memory leak) there's no synchronized/volatile, there's no need for them workers are threads that can execute tasks, execution returns future with task result atomic - way to bypass restrictions of memory model - they can be shared across threads although they hold mutable data