Why Go?

Go is a application-oriented programming language developed by a programmers at Google. One of the major intended applications for Go is writing servers, and so much of the language is written to support this.

Much of what follows is based on the Go FAQ. This is a good starting place for learning about the design of Go.

Some of the major features of Go are:

  • Fast compilation. Go is designed from the ground up for writing large, multi-file programs. In languages like C and C++, compiling and linking multi-file programs is surprisingly time-consuming due in large part to the use of #define to combine files. Many large C++ programs at Google could not be efficiently built on a single computer, and so used a sophisticated distributed build system to make build times more reasonable.

    Apparently, the designers of Go got the idea for creating it during a 45 minute wait for a C++ compilation.

  • Lightweight typing. Go is a statically typed language, like C++ or Java. Yet this is done in such a way that it feels closer in spirit to non- statically typed languages, like Python or JavaScript. You can often avoid explicitly dealing with types.

  • Novel use of interfaces. Go is object-oriented, but it does not have classes or inheritance (at least in the sense of C++ or Java). Instead, interfaces and methods are combined to provide most of the same benefits of traditional object-oriented programming.

  • Garbage collection. As in Java or Python, their’s no need to explicitly de-allocate memory. This simplifies code, and goes a long way towards stopping memory leaks.

  • Closures. Go supports anonymous functions (i.e. lambda functions), which are functions without names. Anonymous functions are allowed to refer to variables outside of themselves, which turns out to be an extremely powerful feature.

  • Concurrency support. Go uses channels and so-called “go routines” (essentially lightweight processes) to handle most concurrency tasks. These are based on a model of concurrency known as communication sequential processes.

  • No exceptions. The designers of Go believe that exception systems in languages like C++ and Java ultimately lead to convoluted code that treats too many situations as errors (e.g. they believe that a failure to open a file should not be treated as an exception). Instead, Go relies on explicit error codes returned from functions, along with the functions defer, panic, and recover.

  • Pretty good standard tools and library. Out of the box, Go comes with useful tools for things like source code formatting (go fmt) and testing (go test). It also has an extensive standard library with many practical packages. For instance, it is relatively easy to create a simple web-server in Go using just its standard library.

Notes on Go

Here are some notes introducing various basic features of Go: