Blake Smith

create. code. learn.

»

Why You Should Learn to Program in Go

Python and Ruby programmers come to Go because they don’t have to surrender much expressiveness, but gain performance and get to play with concurrency.

Rob Pike, Less is exponentially more

I’ve been spending a lot of my recent free time writing lots of Go code. Some of my peers have expressed interest in Go, so I want to explain why I love it, and why you should spend the time to learn it as well.

Why should I learn Go?

The first time I heard about Go, I was quite skeptical. In the past, other Google tools like GWT have left me nothing but confused about their grand complexity. I didn’t want or need another overbearing tool that made its own idiosyncrasies the priority over my own goals. Out of pure curiosity, I watched a Google IO video about using Go in production which spoke to me an important message. For me to invest the time to learn a new language, it must affirm at least one of these two questions:

  1. Is this a language I could realistically use in a production environment?
  2. Will this language grow my ability to solve complex problems in different ways?

After watching the Google IO videos, the answer to both of these questions appeared to be yes. Other developers seemed to be thriving by using Go in production, and I wanted to understand what it was they were talking about. It was at least worth an afternoon trying the Go tutorial to see for myself.

Getting Started

I went through the entire tutorial in about 3 hours. I was shocked that I was having so much fun doing the tutorial exercises - A lot of other language exercises are pretty boring tasks meant to demonstrate the syntax, API and idioms of the language. The Go tutorial not only showed me the basics of its syntax and structure, but also lit up my imagination with the powerful things it could do using just the standard library. I was writing image manipulation code, and web servers within the first hour or so, which definitely got my attention.

Indeed, I found just what Rob Pike said I would. I found a language that brought many of the things I liked about C, got rid of many of the things I didn’t like about C, and added things I wish C would let me accomplish more easily. Who knew programming at this level could be so much fun? Go is classified as a systems language, but in many ways it blurs the line between the power of existing systems languages (C, C++), and more dynamic scripting languages (Ruby, Python). Go addresses many of the problems that make a language like C hard to choose for normal everyday non operating system tasks.

Go has:

  • Simple, minimal syntax
  • Garbage collection built-in
  • A flexible interface system
  • Easy concurrency support via goroutines
  • Fast compilation times
  • Simple compile build/run procedures
  • Statically linked binaries that are simple to deploy
  • Fun to write
  • Much much more..

Is Go for me?

Go’s original target audience was C and C++ hackers. When you read Go code, you’ll see a syntax that echos the C heritage it descended from. After all, Go was written by the same guys who were instrumental in inventing both C and Unix. What’s been surprising about Go is how much complexity and cruft has been stripped away from C and C++, yet their fundamental structures still remain in Go. Ideas such as generics, polymorhpism and object orientation have been reduced to their most simple primitives in Go. Go is so minimal and feels so well thought out, that I marvel at how much I’m able to accomplish with such a small syntax and relatively few language features. Go is clearly a labor of love, with decades of well thought out language design baked right to its core.

Before I programmed in Go, I thought I’d never get much pleasure from working with a statically typed language again. Go is the first statically typed language that has lured me away from the dynamic lands of Python, Ruby and Clojure. When a problem necessitates choosing a language like C, it feels like a chore. Not so with Go. Even if you’re a dynamic language zealot, I bet you’d be shocked how productive you can be with a statically typed language like Go.

How can I start?

If you’re already a programmer, The Golang tutorial is almost all the start you’ll need. Go is one of the first programming languages I’ve learned that hasn’t required me to purchase a book. If you’re coming from Python or Ruby, the syntax should feel pretty straightforward. Beyond that, I always recommend porting a simple project you’ve worked on in the past. This gives you the advantage of already being familiar with the problem domain, and offers a great excuse to focus on learning the language instead of worrying about the problem itself. I picked a toy ascii art image converter I wrote in Ruby and ZeroMQ awhile back and converted it to pure Go code. It was hugely motivating to see my old creation spring to new life with less moving parts, and no native dependencies all in one afternoon’s time.

From there I recommend picking a new project that’s slightly larger in scope. I got even more excited about Go by writing a program that wouldn’t be simple to write with any other language in my repertoire, but was quite simple in Go. If you need any help along the way, the #go-nuts irc channel on freenode has been quite helpful. There are lots of friendly and knowledgeable hackers there who would love to help you.

I seriously hope you give Go a try. I’ve certainly felt a new excitement for programming because of it, and I hope you’ll feel the same if decide to give it a try.


about the author

Blake Smith is a Principal Software Engineer at Sprout Social.