Running OpenGL with Clojure vs Kotlin

This is my experience running some trivial code in LWJGL in Clojure and Kotlin

pancy
2 min readJul 21, 2017

In my last post about my first week at RC, I wrote about my struggle to fit in and find my place while gaining foothold on what I should be working on.

Amidst a melting pot of talented, enthusiastic, and motivated programmers, I decided it was best to wait for my inner calling. Gradually, I remembered my once interest in real-time graphics that had led me into programming. Then consequentially, I stumbled onto Lua and game scripting and the LWJGL engine, most notably used in Minecraft. Since I’ve also been working on a WebVR project, I wanted to dig in. There’s one caveat — I haven’t dabbled in C and Java for quite a while, and I generally prefer not to work with either.

Clojure

This naturally sent me looking for another JVM language that can play nice with LWJGL. Being at RC gave me an urge to explore and learn, so I decided to try out Clojure, a legendary functional JVM language based on Lisp. Since it’s a JVM-hosted language, I thought it’d be perfect for LWJGL, which is a Java real-time graphic engine.

It turned out that I spent two days unsuccessfully compiling some sample code rewritten in Clojure. Clojure is a super fun language to write in, and arguably very declarative. However, the niche is pretty small, and when it comes to finding resource online it’s quite limiting. For instance, there is only one Maven plugin for Clojure out there currently that everyone is using, and it hadn’t had any activity since mid 2016. If you google something about compiling Clojure in a Java project, you would see the same small set of results.

My having the chance to tried working on code projects others can use was great, but one of my 2017 resolutions was to focus more on building things and not tools. That means being language-agnostic and learn to embrace the pragmatic side of programming.

My decision to move away from Clojure for this project was driven by two things:

  • It’s small community and limited support that makes Java interop pretty complicate for newcomers.
  • OpenGL, like any hardware code, is procedural. Adding another layer of functional language just to call Java classes’ static methods most of the time doesn’t seem smart.

Kotlin

Kotlin, as it turns out, is already baked into the latest LWJGL3. In fact, it’s written mostly in Kotlin. While it’s not as “shiny” as Clojure, it’s almost a Java drop-in. With my experience in Python, Go, JavaScript, and a bit of Rust, Kotlin felt very natural. And guess what? You can just copy a Java file, spend a moment refactoring it, and you end up with an equivalence in Kotlin! Using Kotlin lower the barrier of hacking in OpenGL and other libraries which are almost always implemented in C/C++ and have documentation in these two languages.

--

--

pancy
pancy

Written by pancy

I’m interested in Web3 and machine learning, and helping ambitious people. I like programming in Ocaml and Rust. I angel invest sometimes.

No responses yet