4 minutes

I’ve very much enjoyed learning and working with Google’s Golang recently. For those unfamiliar with it, it’s a new, open-source programming language from Google. It’s very similar to C in many way, but it’s like C in ‘easy mode’. It’s got garbage collection, it’s compiler is smart enough to figure out what you mean most of the time without you needing to constantly give it hints by declaring your variable types before hand or constantly peppering your source code with semi-colons. It’s strongly typed, but supports interfaces and type-inference allowing you many of the strengths and benefits of more dynamically-typed languages. It compiles to a single static binary with no external dependencies and it’s cross-compiling is excellent and easy to use.

The best feature by far though is how the language just gets out of your way and lets you actually achieve things you want to achieve. Every issue I’ve ever had with it so far has never been down to some stupid issue with the language or some need to set up complex, complicated bootstrapping code, but my own fault, usually some tiny issue in my own code that I couldn’t see because I was too close to it. I also like the fact that it will allow you to take control if you need to. You can deliberately bypass it’s garbage collection and type-safety features by explicitly stating you are going to use unsafe code (which makes it easy to track down where the bugs are coming from since the source clearly states when it’s entering ‘here be dragons’ territory). I’ve not needed to do this, nor have I spent any time integrating with external C libraries (which apparently is also quite easy) but having that flexibility there if I need it is nice - easy mode is great, but only if you can drop under the hood when you need to.

In Go, my main big project has been an IRC bot for G3 Radio called Leader-1, because making a pun name inspired by terrible 80s cartoons is pretty much mandatory. AT first it had a few issues where I was still learning go and the third-party libraries I was using were having issues as well. However, from knowing effective 0 Go, over the course of maybe 40 hours total dev time, I’ve built a nice bot that scriptable using javascript, has a built-in webserver for debugging and seems pretty rock solid. That also includes the time I’ve spent contributing patches to the IRC library I’m using.

I’ve also written a re-implementation of a javascript ‘image glitcher’ as a command line application I imaginatively called glitch. That was probably my first ever Go app and it works reasonably well.

It’s been a lot of fun learning the language, getting back into writing strongly-typed code after having spent the last 6-8 years mostly in the dynamically-typed world of Ruby, PHP and Javascript. If you are looking for a language for a new challenge, I’d highly recommend Go, it’s great fun.

However, Go isn’t perfect. It’s standard library, while full of great stuff, also has some foibles I’m not too pleased with. The net/http library and the net library in general doesn’t have many sane defaults, meaning the simple ‘works out of the box’ quick start methods are mostly useless for anything serious and you’re required to do a lot of work to get something realistically usable. For example, those libraries do not set timeouts by default and setting them for a http server or client means setting up a complete custom net connection to use. Net connections also don’t get tracked in anyway, meaning if you want to do a forced disconnect for shutting down a particular net service your app is running (like the temporary http debug server in my IRC bot), you can’t because you either have to tracking of existing connections and no way to close them all immediately. There are a lot of rough edges like that, but luckily they are all easy to workaround, if a little frustrating. Since Go is still fairly new, I expect many of these issues to be resolved in the near future.

comments powered by Disqus