Go is a Google experimental open source new language resembling C but adding features like reflection, garbage collector, dynamic types, concurrency, and parallelism.
Presenting Go on the Tech Talk Channel, Rob Pike, one of the main developers working on Go, said the language is experimental because “we don’t think this is the answer to everything, but we are playing and we think it is the time to tell the world about it.” The language has concurrency constructs included in the language and aims to let developers easily create parallel tasks. According to the authors, some of the language’s goals are:
- Combine the efficiency of a static language with the easiness to write of a dynamic one. Practically, the developer can choose to go static or dynamic.
- Safety. The language is type-safe not allowing implicit casts, only explicit ones. Also, the language is memory-safe by not providing pointer arithmetic and doing garbage collection.
- Provide a good support for concurrency and communication.
- Have an efficient, latency-free garbage collection.
- High-speed compilation.
Some of the interesting features are:
- The language has pointers but not pointer arithmetic.
- It has interfaces.
- It has synchronous channels. These channels are used to communicate between threads and is the basis for concurrency. Go encourages sharing memory by communicating it, not communicating via shared memory. Only one thread can have access to a shared value at a time, the values being passed between threads through channels.
- Goroutines. This is another construct used for concurrency. A goroutine is simply a function or a method prefixed by the “go” keyword. A goroutine is associated with a thread and communicates with other goroutines through channels.
- Parallelization. Goroutines and channels can be used to run computations on multiple CPUs.
- Reflection. One can reflect on all types, channels.
- Embedding. It is a simple way of inheritance.
The language has two compilers so far. One comes with different names for different platforms, 6g – 64-bit x86 or AMD64, 8g – 32-bit x86 or AMD32, and 5g for ARM platforms. The other compiler is gccgo. 6g has a mark-and-sweep garbage collector while gccgo has none, but a new one based on IBM’s Recycler is under work for both compilers. There is no IDE nor a debugger yet.
One of the Go’s aims is to have a fast compiler which seems to be attained. The 6g compiler is faster while the gccgo is slower but creates more optimized code. The compiler generates only machine code, no bytecode for a VM, and they say it runs almost as fast a C code being 10-20% slower than similar C code.
There are already many libraries available for basic functions but many more are needed. Godoc generates documentation from source code similar to javadoc. Go is an open source project released under BSD license.
Resources: Go website, Go presentation by Rob Pike.