Language and Platform - fmsbeekmans/jest GitHub Wiki

Clojure is a modern lisp that was made to run on a host platform and to have built-in support for dealing with concurrency \cite{clojure}.

A guest on the host platform

Clojure currently supports the following host platforms:

  • Java Virtual Machine (JVM)
  • Common Language Runtime (CLR)
  • JavaScript

Clojure allows the developer to call functions from the host language as if they were Clojure functions, allowing easy interoperability. However, even though functions can be called easily, the idioms of Clojure differ significantly from the idioms of its host platforms. For this reason many Clojure libraries exist which wrap functions of the host platform.

Easy concurrency primitives and immutable state

To achieve good concurrency support, Clojure follows the functional programming paradigm where possible. Functional programming here means programming without side-effects (The result of a function directly follows from the input with no other effects). The absence of side-effects makes it easier to test functions, as the result is only influenced by it's input, therefore less situations need to be tested and there is no need for mocks (in the functional parts). To be able to work this way, most state in Clojure is immutable unless stated otherwise. Instead of changing the state, a function will often return the new state. If this state is a composite, all the values that stay the same will be memory shared with the old state.

For state and concurrency management Clojure offers 4 different data containers.

  • Vars: comparable to pointers A var points to a piece of state and can be pointed towards another piece of state in a certain thread, changes are isolated to a single thread.

  • Refs: can only be changed within a transaction. This ensures that multiple refs will either be changed together or not at all. Doing so guarantees that the state will always be consistent.

  • Agents: are used to store state that can be updated asynchronously by sending the agent a function to update itself. This is a useful model for entities that operate autonomously.

  • Atoms: offer support for independent state and synchronous changes to it.

Despite its functional character, Clojure also supports polymorphism, a feature often used in Object Oriented languages. Polymorphism is used to specialize behavior of objects at run-time. This mechanic enables the programmer to use best of both the functional programming (FP) and object oriented programming (OOP) worlds.

The Read Evaluate Print Loop (REPL)

Clojure development is usually done with an open REPL, which is an interactive process which accepts (reads) Clojure code forms, evaluates these forms and then prints the result. This allows the live modification of a running program. The availability of a REPL gives the developer instant feedback on small code snippets. This way of developing is called REPL-based development.

Platform

Picking a platform is a very influential decision for any project. The platform can constrain an application in certain ways as different libraries are available for different platforms. The advantages and disadvantages will here be described and compared with one another.

Considerations

The following is a detailed list of our considerations by which we compared the different environments.

  • Ease of development: In the short development phase for this project, it is important to quickly get a working prototype up and running. The platform needs to be mature enough to comfortably develop in and have sufficient debugging options. Furthermore, building must have reliable and reproducable results.

  • Performance: The platform must not significantly limit us in graphics and gameplay options.

  • Ecosystem: The platform may offer or lack important dependencies that are required for the development of the traffic game. Important dependencies are support for rendering, audio and touch input.

  • Prior knowledge: Prior experience is a big factor in accurately estimating development speed.

  • Target environment of the platform: The target environment needs to be suitable for the game and should not limit the user experience.

The CLR

  • On the CLR, Clojure does not provide dependency management tools, a build system or a test platform. This makes the CLR implementation of Clojure the least supported implementation, causing development to be relatively awkard and less maintainable.
  • The CLR has good support for graphics through DirectX
  • Touch event handling is natively supported in .NET, with no extra dependencies necessary.
  • The team has little experience of the de facto libraries on the .NET platform.
  • The platform has mature support for a wide variety of applications including games.

The Java Virtal Machine

  • The JVM is the main target of Clojure. The JVM implementation of Clojure has the most mature tools and the largest community.
  • The JVM is not a platform often used for games, but OpenGL libraries are readily available, and support should be strong enough for a prototype and probably more.
  • Because the JVM is Clojure's main target, there is a wide variety of libraries available. This includes good rendering support for 2D and audio support.
  • The JVM is somewhat lacking in its support for touch input. However, during the orientation phase the team was able to quickly develop a usable library for this purpose.
  • Every member of the team has worked with Clojure on the JVM to some extend and is comfortable working with it.
  • The target environment is suitable for the performance needed for rendering and event handling.

JavaScript (ClojureScript)

Clojure has an implementation in JavaScript, called ClojureScript.

  • ClojureScript has a working build system but only minimal support for unit testing.
  • JavaScript is inherently single-threaded. On a multi-core system this leaves much of the CPU unused.
  • OpenGL is supported both in the browser (through WebGL) and in NodeJS (a non-browser JavaScript environment) through C bindings.
  • Prior knowledge in the team is limited.
  • ClojureScript can be used in the browser with limited support and in NodeJS with unidiomatic support.
⚠️ **GitHub.com Fallback** ⚠️