Exploring golang with a REPL

It is customary for users familiar with a command-line shell or dynamic languages such as Python to work with a REPL, or Read-Eval-Print-Loop. This kind of interface is very powerful for common exploratory tasks: quickly interact with some data or object, prototype an idea, or learn a particular functionality or library.

Unfortunately, static languages such as Go do not provide such an interface, and the common way to perform those tasks is to fire up an editor and write a small program. Granted, the fast edit-compile-run cycle of Go makes it very easy, but it is still not ideal. Another common Go solution is to use the Go Playground, which still requires writing a full program before executing it.

Fortunately, some projects are trying to close this gap, and gore is one of them. Once installed, just type gore and you are brought into an interactive shell waiting for your input. You can then enter Go statements, import packages, view documentation, examine variables, and receive an immediate feedback, all the while benefiting from line editing and code completion. Furthermore, since behind the scenes gore works by generating a program from your input, compiling it, running it and presenting the result, you can at any time view and save the generated program, ready to be used as a basis for your project.

A similar idea but with a different approach is yaegi. This project is more of a Go interpreter, which can be used as an interactive shell, but also as an embedded interpreter in regular Go programs (think eval()-ing Go code at runtime), or as a script interpreter (to be used in the shebang line).

These tools definitely blur the distance between static and dynamic languages, and can bring significant new tricks up your sleeve.