Hiya, I'm new to kotlin (coming from Typescript) a...
# getting-started
t
Hiya, I'm new to kotlin (coming from Typescript) and was curious what best practices people are using to managing app state? I've got a several projects I'm considering kotlin for (server, mobile, and web) and I'd love to have a shared core across all -- so this query isn't strictly about one setup. I am leaning towards the Flux/Redux design pattern as I am familiar with it and I think it makes sense once you've wrapped your head around unidirectional data flow. But I can't find much written about Kotlin + Flux. Is there a preferred approach someone here might be able to direct me to?
r
You can find different redux implementations for Kotlin. Some of them are multiplatform. But there is no "preferred" solution. https://reduxkotlin.org/ https://github.com/freeletics/CoRedux https://github.com/gumil/Kaskade
t
Thanks! I had found those in my research, but I was worried about pushing my Typescript background onto Kotlin if there was a preferred approach
it sounds like there isn't so i'll stick with redux kotlin then!
Any suggestions for a server framework? I've been looking at javalin and spring boot but I'm currently leaning towards Javalin because it seems simpler
r
spring boot is probably most mature and complete
Ktor is a framework made by JetBrains
t
ahh yes i had seen ktor as well
r
There are many others (Javalin, Jooby, Micronaut, ...)
t
the tyranny of choice!
r
If you are coming from JS/TS you can also try Vert.x
t
any preferrence?
r
I use Spring Boot
t
👍
i'll give it a try
thanks for your suggestions
🙏
r
you can look for more info on #server channel
t
will check it out ... just saw there's a redux one as well
l
I'd really recommend ktor, It's by far the most "kotlin-y" option out there. The DSL-syntax to build your application is pretty nice, and it is fully based on coroutines making it very easy to use with the whole kotlin plattform. With regards to redux-like architecture: I'd recommend thinking about building your own implementation. Most libraries try to be as general-purpose as possible, which might fit your needs, but it might also not. If you want to go that route, I'd recommend looking up "The Elm architecture". It's a state-management architecture designed for the Elm language, a pure functional frontend-language. The whole Redux / Flux architecture is inspired by TEA. I'd say implementing something simmilar to the elm architecture should be pretty straight forward, as can encode the different Messages (things that encapsulate events that will result in state-changes) using sealed-classes ;D
👍 1
t
great thanks for that! i'll defo add ktor and elm architecture to my research list! 🙏
l
I'd say Ktor is also a lot easier to learn than the Spring stuff, because it does not rely on any implicit connections (no annotation based bean-stuff)
t
my server requirements aren't particularly advanced so simplier is probably better for me
have you done anything with graphql in kotlin?
l
I have, although it has been some time
t
which library did you use for that?
t
ahh nice with ktor k thats perfect
is junit the defacto test runner for kotlin?
l
I'd say there is no "defacto" test runner. JUnit is propably still the most popular, and it does work great. If you are experienced with JUnit, there is nothing wrong with it. If you are wanting to check out something more kotlin-esque, I'd recommend giving https://github.com/kotest/kotest/blob/master/doc/reference_3.1.md a try
It give's you a bit more flexibility and makes it a bit easier to specify simple tests, imo
t
👍
this might be a really stupid question ... if my src folder only has my code, and only kotlin code, do I still need to keep everything under the common package name (main/kotlin/com.example.mystuff)? or can i omit main/kotlin/com/example altogether?
l
you can structure your project however you want, but I'd recommend staying with the JVM tradition of using
com.example.mystuff
for package names, and I'd also recommend keeping the
main/kotlin
part as it is the way gradle expects your project to be structured, so if you change it, You'll need to tell gradle about it which can get confusing ;D
t
ahh k
i'll have to bit the bullet then!
but damn that directory nesting is extreme!
l
It's not really a problem, as long as you use an IDE like IntelliJ you won't really notice it
t
I've switched from VSCode to IntelliJ for my testing
the sheer quantity of options inside the IDE was initially overwhelming ... but i'm getting use to it quickly
l
yes, it can be overwhelming, but IntelliJ is a pretty genius piece of software that I'd not want to live without ;D
t
i can see myself coming to like it very much
although VSCode has some great features (live share and remote development for example). I haven't seen anything like that in IntelliJ yet
l
a Live-share alternative for IntelliJ is currently being developed, as I've heard
t
ahh perfect!