How we use Clojure at King to write a game engine editor

Here at King, we use multiple technologies across the board. We even produce our own game engine technology to make sure our games load quickly and do not abuse your phone battery. We also use the much discussed and still quite exotic, Clojure, to build the editor for our Defold game engine.

Why Clojure?
Clojure allows us to modify code at runtime without having to restart the editor. This is especially convenient when developing an application with lots of state and UI elements so that you can immediately test your changes in the running editor. Also, with such a complex tool as a game editor, there’s a need to process and transform lots of data. Clojure is very suitable for this kind of task.

While there are other languages that could be a good choice for a game editor, Clojure hits the sweet spot in that runs on the JVM, which offers cross-platform functionality out of the box. We develop the editor primarily on macOS and only need to do minor tweaks to adhere to the conventions of the other platforms. The fact that we could leverage some existing code from the old Java-based editor also played a big part in choosing Clojure for the new editor.

Why not Clojure?
The Defold game engine runtime is written in C with few C++ features rather than Clojure because the runtime needs to have a good control of memory and resources, and needs access to low-level system calls that are available in C. While it is possible to write a game engine runtime using a functional programming language, we think C is still a better choice for this kind of task.

We’d also highlight that Clojure can take up lots of memory space, so you should bear this in mind – especially if you’re targeting mobile platforms. When running on the JVM, it tends to grab a large chunk of memory if it’s available in order to give the garbage collector some headroom. Apps could probably make do with less memory, but if you have memory to spare the JVM will make use of it. The garbage collector itself is fast and efficient though.

Learning Clojure
We’ve done a set of internal lectures in order to introduce Clojure to developers coming from a more traditional C or Java background, and we think it may be useful for everybody. Mats Gisselson from Defold’s editor team starts from the basics, then advances to higher level concepts and finishes with a game built purely in Clojure.

The first two lectures have been already published. And you can follow this playlist on YouTube and get notified when the rest is available.

If you like what we do and feel it is useful, then don’t forget to give the videos a like. If you get particularly excited about Clojure, we’re hiring in the Defold game engine team, see the link below for more details.

Visit Defold’s webpage!

Join the Kingdom - Jobs.King.com

Share this article!

Oleg Pridiuk

About Oleg Pridiuk

Oleg Pridiuk travels around the world and talks about the games industry, so is often referred as an industry evangelist. He is now part of King's team working on the Defold game engine, so is often referred to as a King evangelist. He was one of the first Unity Technologies employees, and… you've guessed the evangelist part, right?

One thought on “How we use Clojure at King to write a game engine editor

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.