Discovering a new programming language is fun. Yet, we all make mistakes in the beginning, as we idiomatically repeat habits from other languages.
Because Golo works closely with the Java programming language, it is likely that Java programmers will make some of the following mistakes early on.
Golo does not have a new
operator for allocating objects. Instead, one should just call a
constructor as a function:
# Good let foo = java.util.LinkedList() # Compilation fails let foo = new java.util.LinkedList()
Golo does not have star imports like in Java. Imports are only used at runtime as Golo tries to resolve names of types, functions, and so on.
You must think of import
statements as a notational shortcut, nothing else. Golo tries to resolve
a name as-is, then tries to complete with every import until a match is found.
import java.util import java.util.concurrent.AtomicInteger # (...) # Direct resolution at runtime let foo = java.util.LinkedList() # Resolution with the 1st import let foo = LinkedList() # Resolution with the 2nd import let foo = AtomicInteger(666)
Keep in mind that instance methods are invoked using the :
operator, not with dots (.
) like in
many languages.
This is a common mistake!
# Calls toString() on foo foo: toString() # Looks for a function toString() in module foo foo.toString()