Hacker News new | ask | show | jobs
by andrewstuart 3326 days ago
Is there reason to choose Kotlin if you don't already live in the Java world?

Put another way, is it a language that makes living in the Java environment less painful, and thus only of value to people who continue to need to live in the Java world?

Why would someone who has never programmed in the Java ecosystem use Kotlin?

I'm surely ignorant and prejudiced but when I read this I thought "Hey why not try Kotlin?", then I thought of Java and images came up in my head of thousands and thousands of files being installed, and the vast, lumbering Java engine cranking slowly and chugging and masses of XML configuration up the wazoo for everything and I shuddered and thought "I'll stick with JavaScript, where the pain of configuration is merely excruciating, as opposed to the pain of Java configuration which is similar to bowing before throne of the Java king of ninth level of hell awaiting punishment for a lifetime of sin.".

2 comments

You can compile Kotlin to Javascript, as a start. You get the benefits and drawbacks of static typing and object-oriented (or rather "class-oriented", if we call Javascript object-oriented) programming support.

But if you choose to stay with the JVM, you get:

- the JVM - multithreaded, highly tuned and high performance JIT VM, well documented and continuously being improved

- mature tools

- libraries from the Java ecosystem - for pretty much anything you can think of

- coroutines (with Kotlin 1.1) for async support.

XML configuration is being phased out slowly (I guess you are talking about Spring here), in the last ~10 years annotations have become much more popular. You still have to support those legacy apps though.

This made me laugh: "then I thought of Java and images came up in my head of thousands and thousands of files being installed" - well, don't check your node_modules directory then, or you might be in for a surprise :)

And Kotlin is targeting LLVM too. It's too early to tell how that will work out considering that much of Kotlin is dependent upon Java libraries, but it's promising.
> You can compile Kotlin to Javascript

Java (GWT) has been compiling to JS years before Kotlin was even a twinkle in JetBrain's eye.

I can't think of a language that doesn't compile to JS.

For certain classes of problems the JVM just cannot be beat. Its a phenomenal bit of tech that laps the competition, especially with regard to large data sets, concurrency support, and instrumentation. Unfortunately, Java the language is fairly painful to work in (less so every release but still). Kotlin makes that particular problem less of an issue.

Even in plain Java though, your description of "the vast, lumbering Java engine cranking slowly and chugging and masses of XML configuration up the wazoo for everything" is largely only applicable in Enterprise software. Modern Java shops tend to eschew all those things and have for quite some time.

Could you dig in a bit more into how the JVM laps the Erlang VM in terms of concurrency support and instrumentation?
Erlang is probably the closest competitor to the JVM and is a fine VM in its own right (especially for classes of concurrency problems that can operate independently).

But if you are dealing with a big interconnected data set that also needs to be concurrently accessed the Erlang memory model doesn't work as well as the JVM one.

For the kind of concurrency model that Erlang is offering it is great, but the JVM offers more variety, so that you can craft your concurrency to your problem instead of being shoe horned into 1 model.

I'd add that the commercial offerings for the JVM (and alternative JVMs like Zing) make the ecosystem more rich than the Erlang one as well.

Finally, I'd say that Erlang suffers from a similar problem to Java, that is, the VM is without peer for certain classes of problem but the ergonomics of the language make people choose other solutions. I think that is a shame as I'd like to see more solutions built on top of BEAM.

I should note, I've not programmed on BEAM for production purposes, only for small projects, but the reason for that is largely those that I mention above.