Choosing Functional Programming for Our Game

In the last couple of months I have been learning how to program. The decision to sit down and learn how to code came inevitably despite my enormous efforts to avoid it up until now. As I mentioned in my previous posts, my plate is already full with 3D graphics, game design, marketing and business stuff, etc. And those nightmarish memories of the “Java for Biologists” course I took during my BSc degree might have also had something to do with it 😉 BUT I am the only one on our team that is working on the game full time, so I had to get over my distaste for ‘if’s and ‘for’s.

It hasn’t been easy. Extreme growing pains would accurately describe the situation- but I am getting to the point that I can handle our basic Unity scripting needs. I started off learning C# on Udemy (Programming for Complete Beginners and Learning to Code by Making Games which I recommend for designers interested in C# coding). The original idea was that I would script in C# and @spacepluk and @Morantron (our programmers) would script in Clojure. They LOVE Clojure- a Functional Programming language that can be used with Unity thanks to the Arcadia project (more about that below). Funny enough, I seem to find the logic of Object Oriented Programming a bit strange, and I naturally tend towards the Functional Programming way of thinking too. So we decided! Functional Programming it is.

Many programmers dismiss Functional Programming as a thing of the past (originally LISP was invented in 1958), or a strange aberration with weird syntax and tons of parentheses meant for academics alone. But we think that after the initial effort of learning the language, its benefits are well worth it and they pay off really quickly, especially in Game Development.

There were a couple specific features of Functional Programming that particularly appealed to us. First and foremost, simplicity. The code is shorter and more manageable. You express more with less code, and not by turning it into undecipherable gibberish but by making it more general and minimizing repetitions. That also means less room for mistakes 🙂 But when you do make a mistake reasoning about your code is a lot easier.

But the real icing on the cake is Live Coding. If you develop in Unity you know the pains of making changes: compiling, deploying, checking the result, rinse and repeat. Again and again and again. It is a time consuming and annoying process. It really gets in the way of creativity because you don’t have an immediate connection with the thing you’re creating (you should really watch Bret Victor’s video “Inventing on Principle” on the subject). Live Coding allows for really quick iterations. You change the program while it runs and see the results in-game immediately (yes, even on your phone!). Without compilations, redeploying to the device, going back to the screen you were testing, etc. Its amazing. Once you have tried it you won’t know how you lived without it. See for yourself:

Live Coding with Arcadia and Unity:

Live Coding with Arcadia and Unity (Android Phone):

So, how do we use Clojure in Unity? Arcadia is a project developed by Ramsey Nasser and Tims Gardner. It integrates Clojure and Unity 3D. As they describe it: “It brings a live coded, functional, dynamic, Lisp to the industry standard cross-platform game development tool.” There is an ever-growing community that is pitching in to help develop Arcadia and bring Functional Programming to a Unity Engine near you 🙂 Check out their repository and community discussion to see for yourself. And let us know what you think!

Thanks for reading 🙂




Choosing Functional Programming for Our Game