Quick prototyping with a Golang REPL
I miss a REPL when coding in Golang. It turns out we can have a Go REPL connected to our IDE of choice.
Why use a REPL?
Because it allows rapid experimentation and gives feedbacks instantaneously. Will my complex regex work? Instead of double-checking everything let’s just eval one case. When selecting a substring is the last index exclusive or not? Instead of reading the documentation let’s just try it out with an example.
Data scientists usually do this with Jupyter Notebooks, for example, but this is a practice which still isn’t ubiquitous in the backend/frontend/devops scene.
For more use cases, please check one video about REPL driven development.
How to configure it?
First install gore. Then integrate it with your IDE.
I’ll highlight my configuration with VSCode but other setups should be similar.
I simply added the following keybinding to “vim.visualModeKeyBindings” and “vim.normalModeKeyBindings”:
This way, whenever I type
<space>+l+t the highlighted text will be sent to the REPL session, provided that I run
gore in VSCode’s terminal window. If there’s no selection, the current line will be sent.
- gore is somewhat slow. But still is faster than running an adhoc test case +
go testfor the same purpose or setting up an adhoc entrypoint +
- depending on the modules imported by your project it may not be trivial to replicate the same imports to your gore session.
Does this work for other languages?
Yes! Your shell is a REPL in some sense. When writing long
fors or commands with many pipes this may come in handy as well.