At this year’s excellent Google IO conference, one session was dedicated to a technology that could one day see wide adoption: a new programming language from Google called Go.
The language has its origins in the work on Plan 9, the operating system designed and implemented at Bell Labs in the 1990s. Two major contributors to that OS were Rob Pike and Ken Thompson, both of whom are now Google engineers and major contributors to Go. The goal of the language is to move against the complexity of modern languages and to provide an alternative that is easy to program, fast to execute, object-oriented, and which generates small binaries.
The easy-to-program aspect is a key feature. By it, the Go team means that simple expressions can represent most of the language’s actions. The so-called “ceremony” of writing expressions and functions is especially eschewed. In presentations on Go, Pike refers to this eloquent statement by Richard Gabriel, a major figure in Lisp circles in the 1990s, as a guiding light: “I’m always delighted by the light touch and stillness of early programming languages. Not much text; a lot gets done. Old programs read like quiet conversations between a well-spoken research worker and a well-studied mechanical colleague, not as a debate with a compiler.”
Per Pike’s explanation, the problem of complexity has its roots in the transition from C to C++, when a thick layer of language features was poured over a tight, efficient, compact language in order to make it object-oriented. Then came Java as a partial attempt at simplification, which slowly became progressively complicated. Thereafter, various scripting languages tried to restore simplicity, but at the cost of performance and runtime safety.
Go is an attempt to leave this heritage behind, start from scratch, and reset the language world back along its original trajectory. It aims at being comprehensible, compact, statically typed, and adorned with good support for parallel environments and scalability.
How well the language meets these goals is open to debate, but the releases currently available do indeed show the compiler to be blazingly fast. Various demos by Google (easily found on the Web) show compilations as near instantaneous, even when run on laptop machines. Google estimates compilation speed to be about 5x faster than gcc. This is achieved in part by greatly reducing the processing of header files and import statements.
As to the language’s ease of use, I see several encouraging developments: Go is garbage-collected. There are no classes, which initially will appear confusing to traditional OO users. However, there are objects, and all objects, including primitives, can have methods. Objects must satisfy interfaces, which are the constructs that most resemble a class. These interfaces tend to have a limited number of methods. Objects can satisfy many interfaces, and this design permits the closest equivalent of inheritance. Go does support closures.
Parallel programming is done through what are called goroutines. This term, an echo of coroutines, is essentially a computational thread. It communicates with other goroutines via a designated channel, which is a synchronous interchange medium. At execution time, threads are swapped in and out of processor execution pipelines by the operating system.
Go provides memory safety mechanisms: Pointers are allowed, but pointer arithmetic is not. All indexing is bounds-checked, and all variables are auto-initialized. These features do not prevent direct programmer control of memory, which can be specified in the same way C/C++ developers have done for years. And for low-level work, the language offers bit twiddling operators and unsigned numerical types.
At a higher level, some convenience designs provide other help. The language is statically typed, but type is frequently inferred from the initialization, thereby diminishing the need to specify it explicitly. Go method names cannot be overloaded (I’m undecided whether this is a plus or not).
Go is starting to work its way from the experimental stage into production work at Google. This is good news, as it would be helpful to have a new language that provides these features and that is strongly supported by a vendor that is deeply committed to developer technology.
At the moment, the key limitation is that Go runs principally on Linux and Mac. The Windows version requires MinGW. (When will it become widely recognized that if you’re relying on MinGW, you have not ported to Windows? That is, no more so than running Windows apps on Wine is a valid port to Linux. They’re both ways to enable developers to compensate for their non-portable code.) Whether a true port will be forthcoming, especially from a team of dyed-in-the-wool UNIX developers, is unknown. Save for this important limitation, I, for one, will be looking forward to experimenting with the language.
Andrew Binstock is the principal analyst at Pacific Data Works. Read his blog at binstock.blogspot.com.