Why Go Is An Excellent Modern Programming Language

Since I began talking about the Go programming language I've been asked why I like it so much. This post is a response to those questions. For those of you who don't know, Go is a fairly new compiled programming language designed for concurrency and modern hardware architectures.

At the core of all of the reasons for liking Go is that it is an engineered language. Some programming languages I've used were hacked together over time. Others were created academically. And still others were designed in a different age of computing with different problems, hardware, and needs. At the heart of Go is that it was engineered to solve problems with existing languages and tools while natively taking advantage of modern hardware architectures.

Avoiding Silly Arguments

When a coding project moves beyond one developer style immediately becomes part of the conversation and can often shift to a debate. For an example, just look at the PHP community, the number of coding standards, and the discussions around them.

In the documentation called Effective Go. It notes that,

Formatting issues are the most contentious but the least consequential.

Go handles this in two ways. First, Effective Go provides formatting guidelines and commenting guidelines. There is no need to debate between tabs and spaces because there is already a guideline. Second, go provides a command to format code to follow the guidelines. It's as easy as using go fmt.

A Tool Chain

Writing code is more than just writing the code and executing it. There are elements like documentation, testing, package management, and more. These elements are even more important when different libraries or packages need to work together. Thankfully, Go has solutions out of the box for these. Here are a few examples:

  1. When the code is commented per the guidelines go doc can be used to get the documentation for anything in a codebase. go doc is the PHPDoc, JavaDoc, or Doxygen of Go. It can get documentation at the command line, it can generate a website (golang.org is powered by it), and more. And, if you follow these guidelines in a project it is compatible with GoDoc, a documentation site for projects on Github, Google Code, etc.
  2. Testing is built right into the core of Go. In the document How to Write Go Code there is a section on testing using go test. This is one of the easiest testing setups I've ever used.
  3. Modern applications are made up of many packagers. The rise of package management tools over the past several years has really shown this off. Go has built in package management that works with git, Github, Mercurial, and so much more. For example, if I want to parse and work with html5 documents in Go I could get the library being used by the Go team at Google with go get code.google.com/p/go.net/html. To learn more about this read up on go get.
  4. Almost all software development is maintenance. Very rarely do we get to start a new project. Even feature additions to an existing project are maintenance because we live in the current code debt of the project. When a pattern or way of doing something changes in a codebase it can be hard to keep a codebase consistent. Often we can end up with multiple ways of doing the same thing and inconsistencies. Go provides a really useful feature called go fix. It uses patterns to replace an old API with a new one.

Each of these parts of the tool chain help with real world and practical development problems.

A Powerfully Simple Language

When I started using node.js I was reminded how fast software can be, how using resources well (e.g., asynchronous communications), and how low level access to communications could improve web based software architecture. I was also reminded of limitations. For example, effectively using multiple core processors. Or, how to effectively write an asynchronous program we ended up with a JavaScript style. Sure, it's not all that hard. But, it's different enough to cause context switching issues.

Go was engineered to be useful and easy in so many of these spaces. Here are a few examples:

  • If you are familiar with C style languages, PHP, Python, or many others the syntax is fairly easy to pick up. It appears to have been designed to be simple and easy to learn.
  • Through the use of go routines and channels there can be multiple "things" happening asynchronously on different processing cores.
  • It has garbage collection. In many compiled languages you manage your own memory. There are two complications with that. First, I (and many others) have gotten used to memory management being done for me. Some will call this lazy. I call this useful. Second, imagine memory management with different routines on different processing cores. It gets complicated and if manually managed offers many places to introduce memory leaks. Go takes care of that for us.
  • Performance is a key feature these days. Performance means a better experience for end users and fewer resources needed to power an application. In testing for my types of use cases Go provides the elegant use of multiple cores, loads of features, and has faster performance than the other languages that are a good fit for the projects. Sometimes significantly faster performance. For example, I've written tests in PHP and Go. Go can compile and execute faster than PHP does it's thing. I'll just put it this way… go compiles fast.
  • Over the years of using dynamically typed languages I'd gotten spoiled at the ease of using dynamic typing. I had expected Go, being statically typed, to be more work to deal with. It couldn't be further from the case. This is the easiest experience I've had working with static typing and the ease of transitioning between types. And that's even without the use of Go interfaces (which are just a fantastic feature).

I could go on and on about Go.

When I look for a programming language I'm looking at a tool to solve a problem with a solution I can live with and that solves it quickly so I can move on to solving the next problem. Go does this well.

If you are interested in Go checkout the Go tour. This tour will walk you through the language while letting you try it right in the browser.