Friday, March 18, 2016

Kotlin and FSharp and Scala! Ocaml!

After re-writing ShmupWars using idiomatic FSharp, I had my ML epiphany. Immutable is good. But FSharp syntax seems a bit rough, and it's hard to be original in Unity, so I'd like to find an alternative. Another strong cross platform game environment is LibGDX, and the jvm has functional languages. But I have limited experience using the jvm, and find the whole java ecosystem intimidating and confusing.

So, first up Scala 2.9. Scala is easy to install, and there is a template for LibGDX, it's all here: http://raintomorrow.cc/post/70000607238/develop-games-in-scala-with-libgdx-getting

Both Scala and FSharp were influenced by OCAML. I can do just about the same things in Scala as in FSharp, but with a cleaner syntax. Moving from FSharp to Scala is straightforward, and in about 3 days I had a working example of ShmupWars. I found that sbt, the Scala Build Tool, does a good job of hiding the jvm from me, and I appreciate that. There are Atom plugins for both Scala and SBT, so I can avoid using a big bloated java ide. SBT also allows quick iterative compiles. I like to test continually while I code, and SBT keeps up with me.

Second, Kotlin 1.0.0. Speaking of big bloated java ide's, Kotlin installs with IntelliJ Community Edition 15. I used Obviam's template http://obviam.net/index.php/libgdx-and-kotlin/ to get started. I couldn't get it to compile from the ide. LibGDX includes command line build scripts, so I installed the kotlinc command line compiler.  IntelliJ keeps trying to reconfigure kotlin, and when it succeeds, the compile script is then broken. So, I'm using Atom with the kotlin-language plugin. Compile iteration is slow. I probably don't fit Kotlin's demographic. They are targeting existing java progamers who would know the secret to fix this snafu. Did I mention that I hate java?

Some Kotlin features I ran into:
* Destructured assignment won't compile unless I list all properties. That's not very convenient if I want just 2 out of 11 properties.
* Pattern matching is 2nd class. No tuples, no destructuring. It's like the Visual Basic Select statement.
* Rather than use an Option wrapper, fields are marked as nullable, and then must checked for null before each use.
* No native immutable linked list.

In the end, Scala is a more mature ML language. Coverting ML idiom from FSharp to Scala was like falling off a log. I was almost disappointed; I thought this would be more of a challenge. I'm sure I just haven't gotten to that part yet.

Kotlin, however does not have first class support for ML idiom. Nor does it promise to - Kotlin has it's own idiom. My original FSharp version uses OOP idiom, would that be a better candidate for Kotlin? I'll give it a try.



No comments:

Post a Comment