I wanted to have a look at Kotlin for a long time now, but when Google announced it as the new language for Android development, I finally took te time to try. And moved Jabit from Java to Kotlin, just like that. I love it!

It’s not so much that it’s easier to write – I still try to define a method the Java way at times – but by removing almost all boilerplate code it makes my sources so much easier to read and understand. This went so far that it helped fix the notorious key exchange bug from my previous post.

From my experience that’s how every Java developer feels when they start using Kotlin. Some may fear that it is but a hype, but I truly believe it has what it takes to make both the Java language less and the Java platform more relevant.

There’s one caveat when you do some byte-pushing when implementing e.g. the bitmessage protocol: Working with bytes is even worse than Java. I have no Idea who thought this is a good idea:

val a: Byte = 1
val b: Byte = 2
val c: Byte?
// does not compile because a + b returns an int:
// c = a + b
// so you will end up with tons of these:
c = (a + b).toByte()

Probably the kind of people that think it’s a great idea that bytes are signed. The only time I ever use bytes in Java (or Kotlin) is when I do relatively low level network protocol or file format work, where I virtually never need a signed byte, and overflows typically are expected to just, well, overflow. An unsigned byte in Java would have made my live so much easier! So long story short, the Bytes helper class is the last remaining Java code in Jabit, that I probably won’t ever migrate to Kotlin.

That is, the ‘demo’ module is still Java, too, and I’m not quite sure yet if I should leave it, have one for each language or if I should rewrite it in Kotlin as well. Any thoughts? Start a discussion with @Abit@mastodon.dissem.ch.