New to Kotlin and portable code questions


Hello there. I'm new to Kotlin. I discovered this awesome language a couple of days ago. I discovered because I saw a post that intelliJ 15 would have it integrated and never heard of it.

At the company I work at we are currently using as3 for the client side + java for the server side to create games for the web and for mobile (using adobe air).
I’m the one that is leading the client side of the development.

I have been some time evaluating languages in order to be able to stop using as3. I tried scala + scalajs, I even started a project in order to be able to compile java to C++ and as3. So we would be able to target js + swf for older browsers and native in some cases + in order to have linear asynchronous like await/async in a single thread as C# does. Scala was SLOW as hell compiling and had some really bizzarre stuff we didn’t like.

I tried typescript, but was too tied to javascript, that wouldn’t allow us to target native. Also module based is not bad but it doesn’t allow us to be completely productive. Also IDEs aren’t the best.

I tried HaXe. Indeed, it was our choice at least before I discovered Kotlin a couple of days ago. I have develop a lot of stuff for HaXe. And tha’t fine. It allow us to target several languages natively. The runtime is small and doesn’t depend on any VM.
It has a lot of things I don’t like. It has a preprocessor that breaks the syntax, and compile time stuff that is pretty scary. It breaks completely incremental compilation, as I discovered with the first language I used with that feature (D) a lot of years ago.
Also the IDE support was pretty bad, so I started that tried to make something like typescript had and then I changed the approach and collaborated to enabling semantic annotations and making it much more usable.
But still HaXe was not the language I liked most.

Swift was an option for the client side, and probably after being opensource it will start to get targets and so on. But it is not opensource yet, and also we would really want to use something that allows us to continue using java on the server side or at least make a migration easier.

So I started a couple of months ago: , was a try to get a language I liked in order to be able to use in a year or a couple of years. Then I discovered Kotlin and saw that it was using almost the same syntax I was designed. And that looked really great. So kudos about that!

So now I’m evaluating Kotlin. I have done a small project: trying to evaluate some things. Though I will probably delete it and make private in the case we end using Kotlin.

In order to be able to create code that works in js and play java I have created 3 folders: one with code specific for js, other with code specifics for jvm and most of the code that works with both implementations.
Then I compile for JS providing the common folder + js folder and jvm with the reciprocal.

Altough it works, it’s pretty annoying. Because one implementation can lack some methods or have some slightly different signatures, also it requires me to have three folder structures and I am propagating the requirement of a library for platform to normal projects.
With explang I wanted to get rid of this without having a preprocessor. I considered several options:

  • static if (as D have,, conditional compilation without breaking the syntax
  • something like: extern class Test { } class Test for js {} class Test for jvm { } and enforcing signatures of the main class, but using the implementation of the proper target
  • having files that are just read for each platform: file.kt file.js.kt, file.jvm.kt but enforces having all the exported symbols in each platform

Also having a single .jar containing all targets would be awesome too.

Which is the current recommended way of targeting js and jvm in the same project? If that is having three folder structures and having a jar per platform as I’m currently doing, is there any plans on improving this?

Is there any plans on implemented await/async or bidirectional generators?

Also, is there any plans on creating more targets in addition to js?

With explang I wanted to be able to target to several places. So I created a fully typed IR AST that simplified the language AST, so creating a target is just iterating that simpler AST and outpuing the proper code/opcodes. I though also into being able to simplify that AST into, converting some stuff to simpler AST, but allowing some targets to benefit of having that extra information.
Would be able to target SWF would be great for us, so we can use adobe air and be able to run on older browsers that doesn’t have webgl support or with a too-slow js JIT. Also targeting .NET would be awesome and would cover all our needs.
I have experience with compilers, so I would be able to help with that if you like the idea.


Our immediate focus with Kotlin is finishing our 1.0 release that will only target the JVM. Once this is out, we'll switch our focus to ensuring a seamless experience when writing code portable both to JVM and JS. We know that there are many rough edges right now, and we'll address them after 1.0 is out, but right now this is not a priority.

We’re most definitely not going to invest into an SWF target for Kotlin, and it’s very unlikely that we would invest in .NET. Of course, the code is open-source and we welcome community contributions, but you should be aware that supporting a new target for Kotlin requires multiple months of full-time work, so it’s not something you could easily take on as a spare time project.



I have read about the 1.0 release, so I won’t make any noise before that milestone regarding to that. But I will report if I find buga.

Also I know a now target it is time consuming. And I would do that in the case I had enough time, and if i drop it before time withoit giving value i just wouldn’t make a PR.

So. Thanks for the reply and good luck with the release.