I'm considering moving a large project from Go to ...
# announcements
s
I'm considering moving a large project from Go to Kotlin. It's too big to rewrite in one go so I need to take a phased approach. What's a good way to call Kotlin code from Go? I need (i) nothing too fancy (i.e. not a framework) and (ii) high performance (there'll be 1000s of calls per second).
g
Kotlin for which platform? JVM/Native/JS?
s
I could go for either JVM or Native as I haven't started yet.
c
Also why are you doing this?
g
it’s really big decision and interop is very different for both those cases
s
@Czar It's a long story - which I intend to write up, TL;DR I need more help from the language than Go can provide, after investigating several others, Kotlin feels like the right choice.
g
for JVM interop you need something like https://godoc.org/golang.org/x/mobile/cmd/gobind
for Kotlin Native you can use C interop https://golang.org/cmd/cgo/
But anyway, I believe it will be not simple transtion if you do this step by step
s
🙂 It's not a simple project, so no change is going to be easy.
s
Could you introduce a message queue or even a http endpoint on the kotlin side (ktor) and offload work piece by piece, 1000s a call a second shouldnt be too much of an obstacle for ktor given the right hardware....
c
I cannot speak about Kotlin native as I'm not very familiar with it. But if you'll end up using Kotlin on JVM, then I'd do it this way: Identify modules (architecturally speaking) in your go project. Code them in Kotlin, use some kind of technology agnostic simple integration protocol (like grpc or 0mq or something along those lines) to call kotlin from Go. One by one move all your business logic to this new Kotlin project while keeping Go project as a gateway/dispatcher. Finally rewrite what's left and get rid of the Go project. Aside from that, rewriting a mature project to completely different stack is rarely successful. Especially if you are not experienced with it.
👍 2
☝️ 1
g
nice idea, not so efficient probably, but much more simple solution
c
Yeah, I would avoid network while implementing my suggestion, that is keep both go and kotlin instances on the same machine so that they are communicating through loopback interface.
s
That was my first idea (grpc)
Also, I have a history of rewriting projects on 'different stacks' and improving them in the process .
r
It’s too big to rewrite in one go
c
Well, if you know what you're doing, welcome to the community and good luck with the undertaking 🙂
s
Thanks
r
It would be interesting to read what you have to say about Go and Kotlin once the process is done
s
Yes - around 10k SLOC and growing. I'll be writing up my trip around various languages and how I settled on Kotlin soon.
v
@Steve Merrony write where? id like to see that, didnt expect that go would be ditched for kotlin so soon 🙂
s
Alexander - thanks for the pointer to ZeroMQ - that might be just right (as a stepping-stone).