Big part of the 1.2 announcement is Kotlin going m...
# announcements
p
Big part of the 1.2 announcement is Kotlin going multiplatform and sharing code. It seems like significant efforts were spent on letting us do this. Also, Andrey Breslav has mentioned several times that they always try to investigate the real-world use before adding any features and try to figure out all the way a feature might be used. So my question is, what kind of code would be actually shared between different parts? I have written my fair share of apps from server to frontend and I don't remember EVER thinking: "Geez, I wish I could reuse this Java backend server code in my JavaScript angular code". The business logic is always on the server, the client takes care of displaying it to the user. There is nothing that needs to be shared, nothing is duplicated.
👍 1
h
I have implemented the exact same form validation logic on the client (for immediate display without a server roundtrip) and the server (for actual validation).
p
What sense does that make though. Server usually does more in depth validation.
h
Also, you should probably not only think of JavaScript & JVM – there's Kotlin native, so you might have a common core in your Android and your iOS app.
p
I am still not sure how Kotlin Native plugs into the multi-platform capabilities of Kotlin. Does Kotlin Native also understand
actual
expect
?
k
Yes, it does but the tooling isn't ready yet
p
ok.. I will admit I dont know much about Android/iOS but at least for the generic spring crud app with react/angular SPA frontend there is close to zero overlap - no code is duplicated..
c
I had many instnaces (and still have) where I'd like to have same validation both on server and on JS, I mean of course format/type validation and integrity validation of input. Business validation is further back, but front-end and controllers/resources validation should be the same, so without sharing code we always have to be cautious and not forget the one when the other is changed. When we get around to implementing shared validation in kotlin multiplatform, at least a dozen developers in our company will be very happy 🙂
t
At least API interfaces and value objects are quite useful to share
Depending on application there is some logic to share as well. For example in VR/AR you might need to do both client side and server math / simulation sharing the related code base.
k
if it has network and DB libraries, you can share business logic and networking code....did that for a Xamarin project and roughly 60% of code was shared but tooling was a pain... Some companies also might want to have business IP in native code for more protection than some sort of VM code that can be easily decompiled...
d
we have several places in our apps (web, ios, android) where we have identical, fairly complicated business logic that we're currently using JS to share. using K instead would be amazing in order to get native runtime performance on each platform and not have to bundle a JS runtime into our android app 🙂 so this is definitely real world for us
g
I imagine more share between client applications on different plaforms (js, JVM, …) than between client and server.
☝️ 2
s
I think it's one of those features where you don't see how valuable it can really be until you actually start using it. I come from the Clojure world where we have libraries that can be reused between the JVM (Clojure) and the browser (ClojureScript) or Node (ClojureScript) and once you have access to that, you start to see a lot more reuse across platforms than you might ever have thought.
c
So, I think we have a consensus here, it's useful, very much so, not to every single developer or product though, which is true for each and every technology out there 🙂