Richard Bucker

scripting in golang

Posted at — Aug 21, 2016

There are a number of choices when it comes to scripting in golang. The first and most obvious is the template library. The point of the template library is to produce a document as a resultset and while data goes in and is partially mutable inside the template there is nothing other than the document coming out. Therefore as a general purpose scripting language it’s not that effective.When golang was younger there were a number of places where people could get reliable vanilla¬†packages. A vanilla package is a package that has no dependencies of it’s own other than the packages supplied with golang. This is a very big problem for nodejs because there is a lot of nested dependencies.All of that mess aside I have many use-cases that are solved by having an embedded scripting language. First and foremost I direct your attention to the SQLite team. They implemented their testing framework on tcl. Historically a new phone came along that did not support tcl and they had to implement a variation of tcl call th1. This was a fine choice because tcl and th1 have a very small codebase and they are easily ported to new targets. It’s that ability to port the tests that allowed the team to leverage their nearly 1M lines of test code. If they had to rewrite the test cases then any number of other issues could have presented.Where to go for embedded scripting languages? One team that popped is the awesome-go. This is a variation on a project that a group of rubyists developed. The idea was to develop a curated list of projects. I’m not sure how well curated the project is but they cover a large set of projects. In this instance I’m looking for embedded scripting languages(link).I followed this project page for a very long time. It was the first one and dates way back. project awesome came much later. Buyer beware!My interest is in 100% go so that projects can be statically linked and not have to worry about more nested dependencies. For example there are multiple lua interpreters. Some are fullblown go and others are API gateways. I have had tremendous success with:otto - javascriptgolua - luagotcl - tclI elected not to try lisp. I’m not a fan. I also decided not to use a new language (this inspiration for this post is¬†zygomys). I’ll never use a customer DSL that someone else designed regardless of correctness or my wrongness as it will be impossible to be in a leadership position. For example the gotcl project is incomplete but it’s also a few thousand lines. The basic functionality is there. I also supports channels. If done right you can get a lot of work done right.