What I love about Go

Jan 25, 2013

The best things about Go have nothing to do with the language.

Single Executable Output

Go compiles into a single executable that runs natively on the target OS. No more needing to install java, .net, mono, python, ruby, whatever. Here’s your executable, feel free to run it like a normal person. And you can target builds for any major OS (windows, linux, OSX, BSD).

One True Coding Style

GoFmt is a build tool that formats your source code in the standard Go format. No more arguing about spacing or brace matching or whatever. There is one true format, and now we can all move on… and even better, many editors integrate GoFmt so that your code can be automatically formatted whenever you save.

Integrated Testing

Testing is integrated into the language. Name a file with the suffix _test.go and it’ll only build under test. You run tests simply by running “go test” in the directory. You can also define runnable example code with output that is checked at test time. This example code is then included in the documentation (see below)… now you’ll never have examples in documentation with errors in them. Finally, you can have built-in benchmarks that are controlled by the go tool to automatically run enough iterations to get a significant result, displayed in number of operations per second.

Integrated Documentation

HTML documentation is built into the language. No need for ugly HTML in your source or weirdly formatted comments. Plaintext comments are turned into very legible documentation, and see above for examples that actually run and can have their output tested as a part of the tests.

DVCS

Support for distributed version control is built into the language. Want to reference code from a project on github? Just use the url of the project as the import path in your code, e.g. import “github.com/jsmith/foo” When you build your code it’ll get downloaded and built automatically.

Want to get a tool written in go? From the command line type “go get github.com/jsmith/bar” - go will download the source, build it, and install the executable in your path. Now you can run bar.

Any git, SVN, mercurial, or bazaar repository will work, but all the major public source code sites are supported out of the box - github, bitbucket, google code, and launchpad.

Other Cool Stuff

Debugging with gdbIntegrated profiling toolsEasy to define custom includes per targeted OS/architecture (simple _windows will only build if targetting windows)Integrated code parsers and lexers.

Do you even care about the actual language anymore? I wouldn’t. But just in case:

C-like

Garbage Collected

Statically typed

…but with type inference so you’re not typing boilerplate all the time: a := “my string”

Implicit interfaces - if a type has the methods of an interface, it implements the interface

Pointers but no pointer arithmetic (thank god)

First class functions

No exceptions

…but multiple returns from a single function so you don’t have to overload return types

Everything is UTF8 (both strings and source code.. yes you can have Θ as a variable name now)