Go go go!!!


Yep, the programming language, by Google. In the past weeks I have been working on a new project using Go, and I must say thing is hella stable, and great to use.

One thing I wanted to do is have the HTTP server run with custom connections. I accept connections from a net.TCPListener and pass these to http.Serve after doing whatever needs to be done.
This required use of a custom Listener object to be passed to http.Serve which instead listened on a chan where I’d push connections ready to be served, requiring skillful use of both goroutines and channels.

The real power of goroutines comes also in the fact that writing non-blocking code is no longer required. No need for complex state machines, handling of events and so on as one would do in C. This makes code that much easier to read, and reduces the risk of bugs.

I’m still a bit reserved about Go’s way of handling errors. Passing along error variables is great and all, but one ends checking if an error happened at each function call (3 lines each time). A sort of macro/builtin that would “eat” the last return value of a given function (provided it is of type error) and return it from the current function if not nil (and all other return values if any would be set to nil) would be very, very helpful.

something, err := someFunction()
if err != nil {
    return nil, err

Would become:

something := safecall(someFunction())

Actually, current error management in Go is so cumbersome it encourages people to ignore errors, which can only lead to catastrophe.