Posts

Showing posts from August, 2017

Go Can Have Variant Types

…how and why to use them   Here I discuss my use-case for variant types in Go , how to implement them, and the pattern I have established for their safe use. I have included some real-world code rather than the traditional Go “animal farm” examples but for the short version skip to the TD;DR at the end. Background I am working on a large spare-time project which currently consists of a little over 7000 lines of Go, I expect that to double before it is released. I started off inspired by an extant Java project which had related aims, but the Java style was very idiosyncratic and I found the code hard to read. For historical reasons I flirted with PL/1 , and that might have been a goer if only it were a little more mature; unfortunately I hit bugs in the compiler which I didn't want to work around. Then I converted the code to good old plain C which was fine until I wanted platform-neutral threads and filesystem I/O. I know there are libraries to solve these problems, b