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

jojo.lichtenberger

11/11/2019, 9:09 AM
Hey, I'd love to use Kotlin in a multi-module Open Source maven project. I've used it in one module exclusively. In other modules I'm currently using Java 13. Would you advise on using Kotlin and Java in a single module? I'd love to switch but don't want to rewrite everything. I haven't tried yet, but I guess the IntelliJ Java to Kotlin Converter for classes doesn't produce idiomatic Kotlin code, so I think it's better to just call the Java code from Kotlin and vice versa. Would you advise on mixing Java and Kotlin in a single module? Are there any pitfalls? Or should I have Java and Kotlin modules seperated from each other?
j

jimn

11/11/2019, 9:19 AM
certain kotlin namespaces occupy the point of no return where java cannot see them. its easy to fix these by converting that java, but sometimes this has a domino effect. strangeness around enums and object and default interface methods can take some time to untangle. if you can decouple the kotlin you will have an easier time for sure.
g

Gabriele Cardosi

11/11/2019, 9:23 AM
HI @jimn These question interest me too. Could you expand a little bit your answer or just point to some documentation of that? I always had the idea that there should be no issue in mixing Kotlin+Java (even if I would avoid that for "clarity")
j

jimn

11/11/2019, 9:27 AM
im porting a giant complex ai system from java and the conversion cornercases are too numerous to plainly list here in a short time. the biggest headaches are booleans using "isSomething" , methods using IsSomething(), getters with parameters, java default interface methods coexisting with abstract class overrides, and finding const attributes when converted from java.
g

Gabriele Cardosi

11/11/2019, 9:29 AM
👍 Thx! I had to port/split a big java monolith to kotlin microservices architecture, and had similir issue. Now It's clear what you are pointing at, thanks again!
j

jojo.lichtenberger

11/11/2019, 9:55 AM
Oh, I think I don't want to spend too much time. It's a smaller project (https://github.com/sirixdb/sirix) but I still don't want to spend too much time. I'll rather introduce a better API for Kotlin users I guess or even a DSL would be great. And I'll probably convert the query module, which is rather simple 🙂
That said I thought Java and Kotlin would be really 100% compatible without a lot of hassle.
j

jimn

11/11/2019, 9:58 AM
wow i was just beginning my travels on time series resampling today!
im writing a memory mapped file data iterator because pandas dataframes really chew up heap.
j

jojo.lichtenberger

11/11/2019, 10:06 AM
Hi Jim, it's not exactly about time series, but to preserve lightweight snapshots of your data (that is store more or less only the changes plus some overhead as for instance some pages of a keyed persistent trie datastructure and neighbour nodes). However, performance should not be hurt and predictable (sliding window algorithm to version data pages) and it doesn't matter which revision is going to be reconstructed performance wise as every revision is indexed under a RevisionRootPage and the RevisionRootPages are indexed, too whereas an UberPage is the main entry point to the storage (quiet some ideas borrowed from ZFS).
A memory mapped file backend would be super great as an alternative to RandomAccessFiles
h

Hanno

11/11/2019, 10:10 AM
I also have two fairly large projects former java, now completely mixed, more kotlin, and i had none of these problems. I can completely advise that you mix it if you want to migrate gradually. Having that said, yes, sometimes autoconversion isn't sufficient. My strategy was to autoconvert classes, look if they compile, if not, revert to Java, Take a look at what concept might cause troubles, quickly refactor it and convert again. From my experience it was mostly not so well written code that caused troubles. But i wouldn't call that troubles at all.
j

jimn

11/11/2019, 10:11 AM
Untitled
tbh java is a stronger language with stronger intellij refactoring features on large scale codebases. kotlin will catch up i hope. the ability to cull 15 years of evolution into a more uniform set of idioms through intellij is indispensable. once it is in kotlin, intellij is going to make very few suggestions about alternatives
it works out that dumbing down to jdk 1.6 code converts better than later garmmars because of the glutinous type information before the diamond operator and val keyword.
h

Hanno

11/11/2019, 10:40 AM
I dont know, my Projects were Java 8 already, like i said, No real problems. Of course java support is still better everywhere, expecting otherwise makes no sense :) but i am very impressed how good kotlin tooling in general worked and how easy it is to have a mixed codebase or to convert from java to kotlin. Of course one should not have the expectation that there wont be any effort, especially when the source code base is not in shape
j

jimn

11/11/2019, 10:42 AM
im just sharing the benefit oof my experience on a codebase that has triggered endless restarts in porting. so many that i had to put it on the back burner.
h

Hanno

11/11/2019, 11:39 AM
I just want to not decourage people from trying it by themselves as it worked nicely for me :)
j

jimn

11/11/2019, 11:41 AM
OP wanted to know the risks. not much point in playing down the risks
https://github.com/jnorthrup/narchy this project is a blast to try to kotlinize. it has everything i mentioned above. plus it has an AI learning how to play pong and tetris and mario simultaneously in opengl.
j

jojo.lichtenberger

11/11/2019, 12:23 PM
As I mainly want to provide the best possible Kotlin API (when the temporal data store is used as an embedded library), I could probably build a wrapper API, which mostly delegates to the Java-API, but has default parameter values, named parameters instead of builders, infix methods such as cursor moveTo 5, instead of cursor.moveTo(5) and such things. Maybe even providing a DSL 🙂 and I could start switching a small module instead of the core module at first.
2 Views