Why a js programer should use kotlin/js? What are...
# javascript
i
Why a js programer should use kotlin/js? What are its benefits?
d
You don't have to write JavaScript 🧌
4
🧌 2
❤️ 4
👍 4
s
@diesieben07 haha
f
I think this is a valid question. And the answer is probably "it depends". For people coming from js, I don't see may reasons to pick Kotlin as TypeScript is probably the more rational choice, but if you know and like Kotlin, it might be a great benefit to share code between js/jvm?
7
r
You can use Kotlin coroutines with Kotlin/JS
s
Well, if I were a JS programmer, I’d go definitely for TS.
c
yes if you don’t want to share logic with other kotlin platforms TS is probably better suited for frontend web development than kotlin
j
@diesieben07 as a non-js programmer I fully agree with that statement. I am making a react app in Kotlin and I am actually having fun 😄 I do not have happy memories learning javascript when I was just messing around with it and learning how to develop. I think the main benefit is using 1 programming language to do multiple things. So as I said, I am now making a react app (as a multiplatform side-project) because now with kotlin I feel enabled to do so, aside from my regular Android development. If you get comfy in kotlin JS, perhaps it is easier for you to also explore other things like Android development or backend development as you can write it in the same programming language. Otherwise, its about which language you like better and I recommend googling that. For me coming from Java (android) development, it was very clear that Kotlin is way better than Java to use. Perhaps it is the same for Javascript.
s
@Joost Klitsie may I know what you are using exactly?
j
@stephanmg for the react app? I am using the kotlin react wrapper in combination with a kotlin material UI wrapper
👍 1
n
Is it must to use Gradle for KotlinJS
a
i would use it for a Kotlin multiplatform project, but even then now with their ability to output typescript definitions (which is still pretty wonky IMO) could make it less likely to use kotlin in the FE part
also it still has bundle optimization issues, so it definitely would increase your bundle size. hopefully the new IR compiler when its ready (still not stable) could do tree shaking and webpack optimizations
ive been trying to make it work on Kedux https://github.com/monstar-lab-oss/kedux but you have to annotate things you want exposed with
@JSExport
and a lot of things including
Flow
from kotlin stdlib is not exported to js with new compiler yet, so I get a bunch of warnings
s
the redux link is broken in the kedux README.md
btw
a
oh weird. thanks for letting me know hehe it supposed to go to redux.js.org
s
yw
@agrosner the link is internal to the document
try http:// or something
👍 1
a
fixed 🙂
✔️ 1
a
I could add additional reason for you. JavaScript is not good to build complicated "fat" logic and both TS and K-JS cover that niche. K-JS integration is already close to TS, so it is a qurstion of background, as it is said earlier. But in fact K-JS and TS also are not good for fat logic because of DOM and JS issues. What we want is WASM. Aaand... Kotlin has WASM. Or will have when it is ready. So it will be quite easy to migrate JS frontend to WASM frontend.
👍 1
i
Thanks
s
@altavir interesting! but is there no other alternative to DOM than WASM?
so one could use virtual DOM solutions, are they equally slow?
I’d expect vDOM to be ~10x faster maybe
how does this compare to WASM?
a
Dom is not fast or slow it is an object model. The rendering is what could be fat or slow. Virtual dom speeds up some things by doing some operations without rendering. Wasm is important when we are not talking not about rendering, but about heavy logic.
s
@altavir yeah I know DOM. I agree, WASM looks promising for heavy duty logic/computation.
just a sidenode: there seems to be also some activity around people trying to transpile JS -> WASM
a
The problem with js and kotlin js in particular is the js ecosystem. The js to wasm converter won't do you good since you will have to work with js.
s
yeah that’s true
i mean this all heavily depends on other factors really… hard to give a overall recommendation to use Kotlin/JS over JS
but I see the benefits of Kotlin/JS here
a
I am doing some heavy logic in browser and I would be happy to bypass js completely.
s
so, with WASM you currently can’t?
a
Wasm tooling is not sufficient at the moment. I am not ready for manual memory management.
s
Oh I see.