On learning Go

I’m often asked about the best way to learn Go. My advice is to take the same approach you should to learn any language: pick a real problem and solve it. It doesn’t have to be big.

My first Go programs were those I wrote working though the exercises of Jon Bentley’s Programming Pearls in preparation for my interviews at Google. (I joined the team a little after Go was launched.) The exercises consisted of various search and sort routines, a hash table implementation, and more along those lines. They were a great way to become familiar with the basic Go syntax, but provided little scope for learning about the standard library or the more interesting language features.

The first real Go program I wrote is a formatting tool for Mercurial change logs, to assist in preparing the Go project’s release notes. In writing it I learned a bit about I/O, strings, maps, and a few parts of the standard library.

Around the same time I began contributing bug fixes and minor features to the Go project itself. Reading and working on the Go core is the single most effective way to familiarize oneself with Go idiom. We have spent a lot of time polishing and refining the Go core, making it an invaluable resource. Next time you look up a function in the documentation you should go a step further and look at its implementation, too.

Things continued in this vein for a while. Any time I wrote a program – any program – I did it in Go. At first I thought this would slow me down, but I was surprised to find that I got over the initial hump quickly. Before long, the kinds of small tasks I would typically write in Python (or even bash) I was writing in Go – and they were better for it. Go being a statically typed and compiled language, these tools were unequivocally more reliable and efficient than they would have been as scripts.

(I’m reminded of something a colleague said to me earlier this year: “Of all the code I’ve written, I’m most proud of my Go code.” With Go I never feel like I’m writing a “throw away” program; they each seem like polished little jewels.)

So if you are looking to learn Go, don’t look too far. Your first Go project is probably right in front of you.

Go Resources: (by no means an exhaustive list)

63111 views and 4 responses

  • Dec 28 2010, 7:39 PM
    Kosei Kitahara liked this post.
  • Dec 28 2010, 8:45 PM
    Gav Newalkar responded:
    Hi there,

    You've got quite an interesting and informative blog here. Great to see another coder in Sydney.

    Gav

  • Dec 28 2010, 11:00 PM
    Amit Agrawal liked this post.
  • Dec 28 2010, 11:07 PM
    Liudas liked this post.