Pirates of the JVM series

Golo — The world didn’t need another JVM language. So they built yet another one

JAXenter Editorial Team

When we launched the Pirates of the JVM series, we promised we would put the spotlight on each and every programming language in the JVM universe so here we go. First stop: Golo. We talked to Yannick Loiseau, co-leader at Golo, about the advantages and disadvantages of this language, its core principles and more.

We are sailing across the Dynamic Sea and you should be able to see Golo clearly now. The Dynamic Sea has a lot of interesting attractions such as Rhino, Jython, Gosu, LuaJ and Golo. The latter is yet another JVM language — but a simple one, according to its national hymn.

Click on the map to see the entire infographic

Golo — Background information

JAXenter: What was your motivation for inventing Golo? What does Golo have to offer that other languages fail to provide?

Yannick Loiseau: One of the main motivations behind Golo was to experiment with the new `invokedynamic` JVM instruction. The purpose was to create a dynamic, yet efficient, lightweight language. It was born as an experiment of the Dynamid research team, which focuses on environments with high dynamic properties, such as IoT, embedded systems or cloud computing. Since March 2016 (release 3.1.0), Golo is an Eclipse Technology Project.

A distinctive aspect of Golo is its dynamic nature. Everything is resolved at runtime. For instance, a module can be compiled even if the modules on which it depends are not available compile time since even the function resolution (kind of “linking”) is dynamic. Another aspect is its tight integration with Java.

JAXenter: Can you describe the core principles of the language?

Yannick Loiseau: Golo is a really dynamic language. Variables are not typed, and type checking is done at runtime, duck typing fashion:

var foo = 42
foo = "The answer is " + foo

Golo is a functional language. Thus, functions are first class values that can be used as function parameters or returned from other functions:

function foo = |x| -> x + 1
# (...)
# ^foo is a reference to the foo function
println(list[1, 2, 3]: map(^foo))
# prints [2, 3, 4]

Closures are supported, as well as many higher order functions to manipulate these.

function adder = |a| -> |b| -> a + b
function multiply = |a| -> |b| -> a * b
let transform = adder(3): andThen(multiply(2))
# prints 42

Actually, under the hood, Golo functions are just static Java methods, so any existing method can be used as a Golo function:

import java.util.Objects
println(list[1, null, 42, null]: filter(^nonNull))
# prints [1, 42]
println(list["a", "aa", "aaa"]: map(^String::length)
# prints [1, 2, 3]
let formater = ^String::format\1...: bindTo("the %s is %s"): asVarargsCollector()
println(formater("answer", 42))
# prints "the answer is 42"

Golo is also an object oriented language that leverages the Java standard library. For instance, the `list[…]` in the previous example are actually `java.util.LinkedList` instances. As such, one can use any Java object transparently, which make it a great glue language to integrate several Java libraries and framework:

import javax.swing
# (...)
let button = JButton("Click me!")
button: addActionListener(|event| -> println("( )"))

But one of the main Golo features to ease Java integration is _augmentations_. Using augmentations, one can dynamically attach new methods to any class.

For instance, this is valid Golo code:

5: times(|idx| {
  println("loop number %s": format(idx))

while `5` and `”loop number %s”` are regular `java.lang.Integer` and `java.lang.String` instances.

Augmentations works on super classes and even interfaces:

augment java.lang.Number {
  function answer = |this| -> this * 2
println(21: answer())
# prints 42

Golo does not provide classes, but algebraic data types (tuples, struct and union) that can be augmented if needed to provide polymorphism.

Augmentations can have names, and thus provide a feature similar to traits or aspects:

augmentation Fooable = {
  function foo = |this| -> "foo " + this
# elsewhere...
augment java.lang.String with Fooable
augment java.lang.Number with Fooable
println("bar": foo())
println(42: foo())

One last wonderful feature is represented by function decorators, which are similar to what Python provides.

A decorator is just a higher order function that can be used to modify the behavior of another function, providing another “aspect-like” approach:

function logger = |message| -> |fun| -> |args...| {
  println("# " + message)
  return fun: invoke(args)
function f1 = |a, b| {
  return a + b
function f2 = |a| -> "hello " + a
let a = f1(18, 24)
# a = 42, prints "# foo"
let b = f2("world")
# b = "hello world", prints "# bar"

A lot of useful decorators are provided, for instance `gololang.Errors::option` transforming a function that can raise an exception into one that return a `java.util.Optional` object.

Hello World example

JAXenter: What would a typical program with Golo look like?

Yannick Loiseau: The classic Hello World would be:

module Hello
function main = |args| {
  println("Hello World")

To show more features, we could uselessly complicate:

module SaySomething
local function say = |prefix, suffix| -> |name| -> prefix + name + suffix
function main = |args| {
  let message = say("Hello ", "!")
  let names = match {
	when args: isEmpty() then list["World"]
	otherwise args: asList()
  let messages = names: map(message)
  foreach m in messages {

JAXenter: For what kind of applications/use cases is Golo well-suited? For which ones it is not?

Yannick Loiseau: As a simple, dynamic language, Golo shares a lot of use-cases with languages like Python or Ruby or, in the JVM world, with Groovy. Its good integration with Java libraries allows us to use it as a glue/script language.

Since the runtime is very light (about 800KB with dependencies, not counting the JRE), it is well suited for small and embedded systems.

On the other hand, being a dynamic language, few checks are done by the compiler, and thus most errors will happen at runtime. If you need a robust system, you’d better have a good test coverage or use a more static language.

Golo shares a lot of use-cases with languages like Python or Ruby or, in the JVM world, with Groovy.

Another consequence of the dynamic types aspect is that at the JVM level, every value is an `Object`, which implies a lot of boxing/unboxing when doing numerical computation, with a huge impact on performance. A solution, as often with this kind of language, is to implement the computational aspects in pure Java, and integrate the system in Golo.

Fortunately, this integration is very easy.

SEE ALSO: Eclipse Golo JVM programming language

JAXenter: What is the current state of the language?

Yannick Loiseau: The language itself is quite stable, and feature rich. However, the standard library misses some must-have modules. On the other hand, Golo can leverage from the rich Java ecosystem, since it integrates well with Java libraries.

Features in the pipeline

JAXenter: How about your plans?

Yannick Loiseau: If we talk about language features, we have some that are ongoing, like tail call optimization or hygienic macros, which is a long-awaited feature. Some issues with Java integrations still remain, to make it as transparent as possible.

Performances are also one of the main concerns. We also plan to experiment with the Truffle/Graal framework.

As already said, the standard library lacks some must-haves, and contributions are welcome!

But the biggest issue is the integration with Java 9 and Jigsaw, which actually breaks some aspects that Golo relies on, and will need a lot of work.

SEE ALSO: Pirates of the JVM — The infographic: Are you ready for an adventure?

The biggest issue is the integration with Java 9 and Jigsaw.

JAXenter: How can people interested in Golo get started?

Yannick Loiseau: Install Golo and start coding! Installation can be done from sources or native packages for Windows, Homebrew or RPM-based distro. Golo is also available from Bintray / jCenter as well as from Maven Central to use in Maven or Gradle. If you want to keep your system clean, we even provide Docker images of Golo.

Most Java-oriented IDEs provide (some) Golo support, although it may be outdated.

The next step is to read the doc. The source repository also contains code examples to help you getting started.

For more information, you could refer to this Eclipse article and of course the Golo Guide.


Yannick Loiseau, Ph.D., is an Associate Professor in Computer Science at Clermont Auvergne University in France, where he teaches Software Engineering and programming. He does his research as part of information system team of the LIMOS laboratory.

He is a contributor to the Golo programming language project since 2014, and the co-leader of the project since October 2016.

Don’t forget to check out the Pirates of the JVM series.

Inline Feedbacks
View all comments