Friday, November 11, 2011

Happy Birthday Go

The Go Programming Language turns two.

I really want to like Go (Commander Pike is one of my heroes, and systems programming currently either means C or a Special Olympics scripting language). But I'm slightly put off by the lack of exceptions, and the seemingly gratuitous concepts offered instead. Does anyone have experience with how this aspect of Go pans out in real world use?


Daniel Yokomizo said...

It added panics later which is kind of exceptions by another name

Evan said...

I write a lot of Go and have mixed feelings about its error-handling. However, I wouldn't change anything for lack of a better alternative.

Maybe panic/recover are the "gratuitous concepts" mentioned? Recovering from a panic is intentionally a little inconvenient to discourage panics for everyday type of failures (file not found, etc.).

Panics should happen only when there's a bug in the code. recover is there to save you from buggy code you didn't write or to make sure that your server never crashes, even if it fails.

I think it's true that exceptions are abused in many languages. They occur all the time for very mundane reasons. I also think back on Raymond Chen's blogs on exceptions[1][2] and find it hard to disagree.

At the same time, error codes are tedious. 90% of the time you're just letting errors trickle up to the caller and that's something exceptions do very well. Go's GC and defer mean there's less cleanup and fewer levels of indentation than the same code in C, but it's still painful at times.