https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
d

Daniele B

03/26/2021, 4:37 PM
I just published a short article: How much can we share in Kotlin MultiPlatform:single modules?data layer?view model? https://danielebaroncelli.medium.com/how-much-to-share-in-kotlin-multiplatform-a-module-the-data-layer-the-view-model-5bb594eb3a2a
👍🏽 1
👍 3
r

russhwolf

03/26/2021, 7:59 PM
I disagree with this paragraph:
When comparing KMP to other cross-platform frameworks such as Flutter and ReactNative, KMP can easily be the winner only if we are sharing both the data layer and the view model. A solution where KMP is used only for the DataLayer would still require a whole lot of platform-specific code, and wouldn’t be particularly appealing for many companies when compared with Flutter and ReactNative.
You can't compare using KMP as a data layer to using Flutter or RN for the entire app. You have to compare to other data layer solutions. And using Flutter or RN as the data layer is much more difficult than KMP.
d

Daniele B

03/26/2021, 8:10 PM
Yes, I see what you are saying. Obviously Flutter and RN are not solutions you can use for just sharing the data layers. The point is why would you choose to share just the data layer, when you can easily share much more? For new projects, companies are clearly very interested in sharing as much as it’s feasible. More platform-specific code means taking longer to complete projects. Competing with Flutter and RN means to be able to share more than just the data layer. In my opinion, KMP can easily win without sharing the UI layer (as nowadays with declarative UIs it’s very thin), but not without sharing the View Model.
r

russhwolf

03/26/2021, 8:58 PM
Competing with Flutter and RN means to be able to share more than just the data layer.
No, it's the exact opposite! Yes, being able to share more than just the data layer helps make KMP competitive against these other solutions if your goal is to maximize shared code in a new app. But the world is not made only of new projects, and the strength of KMP is that it can also do other things. You're basically saying "sharing just the data layer is bad, so don't use KMP to do it", but that's bizarre as an argument against KMP, because if your goal is to share just the data layer then KMP absolutely outshines the other solutions.
d

Daniele B

03/26/2021, 9:09 PM
@russhwolf if you read the article, I am making a distinction between existing projects and new projects. I am saying that for existing projects it makes sense to share with KMP one module at a time. Gradually, this could mean even the whole data layer. When I am comparing KMP to Flutter and RN, I am doing it in the context of new projects. I thought that was clear. Using Flutter and RN on existing projects is basically impossible, so I don’t see how it’s possible to compare KMP to Flutter and RN for anything different than new projects.
To make it more clear, I just pre-fixed that paragraph with “For new projects,“:
For new projects, when comparing KMP to other cross-platform frameworks such as Flutter and ReactNative, KMP can easily be the winner only if we are sharing both the data layer and the view model. A solution where KMP is used only for the DataLayer would still require a whole lot of platform-specific code, and wouldn’t be particularly appealing for many companies when compared to Flutter and ReactNative.
k

kenkyee

03/26/2021, 10:09 PM
You*can* do flutter and R/N on existing projects... 🤔
1
d

Daniele B

03/26/2021, 10:27 PM
@kenkyee mmm… really? that’s interesting 🧐 how much existing native code can you reuse in a Flutter or R/N project?
k

kenkyee

03/26/2021, 10:33 PM
They can interop with native code. How do you think they talk to native APIs?🙂
d

Daniele B

03/26/2021, 10:42 PM
Yes, surely they interop with native APIs, but that would mean having an interface written in Flutter/RN (Dart/JS) and an implementation in Android and iOS. So, passing from 2 languages to 3? Does it make sense?
I guess people would do that when they want to write a new app in Flutter or RN and use some existing platform-specific code. I don’t think it can be framed as “using Flutter and RN on existing projects”, but rather “using existing code on new Flutter and RN apps”. The same would happen on a new KMP app, when wanting to connect to some framework-specific code.
k

kenkyee

03/26/2021, 11:12 PM
It's still better than webviews 😂
m

Michal Harakal

03/27/2021, 7:52 PM
Is it a comparison between KMP, RNs and Flutter still a thing? I decided for me to avoid this comparisons completely. And its a really hard to have a very subjective one, depending from which area you come, your team setup, app you want to build. Technology stack itself should be only a part of a decision... But I like @Daniele B approach with sharing even ViewModels (work well with Android, and Desktop).
d

Daniele B

03/27/2021, 8:41 PM
Surely choosing a framework involves a lot of considerations. But we can clearly see how popular Flutter has become and the reason is without any doubt the shorter development time, which means money for companies. There are a lot of companies that have chosen Flutter or are about to choose Flutter for new projects, which in the meantime are also following what's happening with KMP. And these companies won't be impressed by KMP solutions that require them to duplicate the view model in all platforms.
👍 1
m

marzelwidmer

03/28/2021, 3:07 PM
Great stuff .. I get just in touch with
kmm
basically I am backend developer (spring kotlin) … try to get in the Mobile world 🙂 we have in the company native
android/ios
and web… this
kmp/kmm
is really interesting… I was trying to also support the
jvm
with the
shared code
but I was not really successful 😞 I am used to maven in the backend 🙂 😞. @Daniele B U have maybe a tip for me… It will be also be nice to separate the
android/ios
part in separate
gitmodule
i was trying it with the https://github.com/KodeinKoders/playground-alternate-KMM-architectures but also there i was not successful of missing knowledge of gradle… with the separation I was thinking it will be more easy to push it in the company to the
ios
devs 🙂
d

Daniele B

03/28/2021, 3:13 PM
@marzelwidmer I am not sure I understand the question. You are saying you want to support jvm. For server or for client?
m

marzelwidmer

03/28/2021, 3:16 PM
for server. and if ist possible JS for the web. if the JS is usefull for angular TS this I don‘t know at the moment. in the end we have 3 different clients (andoid/ios and web) the idea was to share some stuff eg business model ( but I know sharing is caring)
d

Daniele B

03/28/2021, 3:28 PM
For web, Kotlin provides some convenient React wrappers. Personally I am more interested in Compose for Web, which should come up soon, hopefully by the end of this year. In this repository (https://github.com/joreilly/PeopleInSpace) you can find an app that is sharing some code with Backend and Web/React.
🙏 1
m

marzelwidmer

03/28/2021, 3:30 PM
thank. this mean not realy for angular with TS ? this good to know.
d

Daniele B

03/28/2021, 3:31 PM
Kotlin doesn’t have a wrapper for Angular. Only for React. But the most interesting will probably be when Compose for Web will come out.
m

marzelwidmer

03/28/2021, 3:33 PM
if I want learn (as backend dev) this KMM. I have to learn (I say them so now legacy xml stuff). ? or I can get strait to the compose? this is more what I like it is almost same like SwiftUI what I saw. there I have some hello world samples done already. what U think? because I think this KMM have really future;)
d

Daniele B

03/28/2021, 3:34 PM
I think it makes sense to jump straightly to Compose and SwiftUI
👍 1
I have recently published a sample app, using the D-KMP architecture, which shares the viewmodel in KMP for Compose and SwiftUI: https://github.com/dbaroncelli/D-KMP-sample
🙏 2