https://kotlinlang.org logo
#announcements
Title
# announcements
p

poohbar

11/29/2017, 4:11 PM
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

hho

11/29/2017, 4:14 PM
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

poohbar

11/29/2017, 4:14 PM
What sense does that make though. Server usually does more in depth validation.
h

hho

11/29/2017, 4:15 PM
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

poohbar

11/29/2017, 4:16 PM
I am still not sure how Kotlin Native plugs into the multi-platform capabilities of Kotlin. Does Kotlin Native also understand
actual
expect
?
k

kirillrakhman

11/29/2017, 4:32 PM
Yes, it does but the tooling isn't ready yet
p

poohbar

11/29/2017, 4:34 PM
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

Czar

11/29/2017, 4:53 PM
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

tlaukkan

11/29/2017, 5:35 PM
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

kenkyee

11/29/2017, 5:37 PM
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

damien5314

11/29/2017, 5:43 PM
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

gaetan

11/29/2017, 6:07 PM
I imagine more share between client applications on different plaforms (js, JVM, …) than between client and server.
☝️ 2
s

Sean Corfield

11/29/2017, 6:48 PM
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

Czar

11/29/2017, 8:03 PM
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 🙂