Adam Smith

twitter github

Thoughts on Go

2013-11-27 21:41:59 +0000 UTC

…after having written this blogging engine in it.

Go tells you to make a $GOPATH directory with a predefined structure - a bin directory, where it sticks your compiled output; a pkg directory for Go libraries, and a src directory for your source. All your Go projects go in there. The fewer decisions I have to make about trivial organizational stuff, the happier a developer I am.

On the other hand, maybe it’s a bit rigid? I don’t know how much one can stray from this structure if they need to, nor can I especially think of any reasons why one might want to. But this sort of thing raises red flags for me - if everything is written to assume a particular structure, and I - for whatever reason - need to stray from that structure, I imagine it’ll often be a pain to get things to accomodate me.

And on the other other hand, it seems a bit half-hearted. If the Go folks are going to define their own own hier(7), where do, say, templates for my blog go? Config files? These things I still do need to think about, and that sucks.

…and seriously, asking me to name my local project directory after the Github URLs it’s hosted at is just gross.

…and worse, there’s no min() function for integers (!) and no ternary operator, so to safely slice the last few elements of a range you need to either write your own min() function or do a big, five-line if-else thing.

The approach to error handling in this language is kind of a mess - it drowns out the interesting parts of the algorithm with tons and tons of boilerplate. See Haskell’s Maybe (or Either) monad for ways to do this right.

Also: why does template.Must() exist? That seems like it should be a generic thing - fail hard on error. Why is it tied to my HTML templates? Oh, right, because…

There’s that thing about the template.Must(). There’s the thing about no generic min(). There’s sorting, which is just insane - for every kind of array I need to define my own length and swap functions! And so on, and so on. The lack of polymetric polymorphism seems to breed warts everywhere.

The tutorials and intro material are good, but the library references and stuff need a lot of work. There’s not enough cross-referencing: html/template, for instance, basically tells you to go read the text/template doc but doesn’t actually link to it. Minor inconveniences add up. It’s rarely clear how to do things. For instance, how do I use a MaxBytesReader to keep people from uploading massive POST requests? Nowhere is it clear that I need to inject it into my Request’s Body.

And how nice would it be if I could get a list of all types that implement an interface? One can only dream.

The compiler is super fast. go fmt is totally a good idea. go get makes everything painless. I just type go build instead of making a Makefile? Using autotools? Setting up a cabal file? No need for a virtualenv or whatever? All so nice.

Honestly, this is a superfast way to throw together a simple/quick webapp, and in terms of speed of development/performance/reliability (some static typing is probably better than none) I don’t think there’s anything better out there right now. Unfortunately.

Right now I’m working on a startup with a D backend, and compared to that it’s hard to say whether Go is better/smarter/wiser. Go knows how to keep it simple where D is a fucking mess, and there’s wisdom in that. But D also is smart enough to include a lot of more powerful, more complicated features that Go is scared of but sorely needs. Similar things apply to Go vs, say, Scala.


Comments

What do you think of Rust?

I’d like to get your thoughts on Rust.

I’ve been dabbling in D and Go since their release, but recently discovered Rust and I really like what I’ve seen. It’s still in the pre–1.0 stage but seems pretty stable.

Posted by F.G. Barletta at 2013-11-28 13:56:50 +0000 UTC

Rust

Rust’s definitely exciting - everyone behind it seems to have their heads screwed on tight and the ideas behind it are super cool. What I’ve perceived as instability has kept me from getting too close, unfortunately. If that’s settling down, and once a suitable project comes to mind, I’d be very excited to check it out.

Posted by Adam at 2013-11-28 15:36:44 +0000 UTC

Add Comment