Tag Archives: go

Return errors or useful values, not both

One of the nice features of Go is returning multiple values natively. e.g. type Foo struct{…} func New() (*Foo, error) { if err := initSomething(); err != nil { return nil, err } return &Foo{…}, nil } What’s interesting is that either the error is nil (and you have a useful value) or the useful […]

Go interfaces are for consumption

After a recent discussion, I’ve realised something about Go’s interfaces. They’re best if you use them as a consumer rather than producer. Using my own code as an example. I have a storage layer that uses bigtable. package storage type IO interface { Read() (string, error) Write(string) error } type bigtable struct {…} fun New() […]

Logging in Go

Dave Cheney has an excellent post, Let’s talk about logging. In it, he dissects the current logging libraries, and what you really need. I pretty much agree with everything he says. Warnings are just more info messages. Log or handle the error — not both. Where I disagree is with the error logging. It is […]

Go Readability

If you haven’t seen them, do take a look at these slides on Go readability, from one of Google’s Go readability group. Readability is an important process at Google. In theory, it’s about ensuring the style guide for a language is applied. In practice, it’s also about ensuring that idiomatic code is produced. This is […]

Happy Fifth Anniversary, Go

So, Go is five years old. Looking back through version control, my first bit of Go was in May 2012. I’ve been using it as my preferred language for the last year or so. It still feels very pleasant and easy to work with. In no small part that’s due to the excellent tooling. The […]

Go Strings

I’ve been looking at Go recently. It’s a pleasant language, with few surprises. However, I wondered (as always) what the encoding of a string is supposed to be. For example: Python 2 has two types: str, and unicode. Python 3 has sensibly renamed these to bytes and str, respectively. Perl has a magic bit which […]