The Go gopher was designed by Renee French (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
The Go gopher was designed by Renee French (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously. There are several trends:
Computers are enormously quicker but software development is not faster.
Dependency management is a big part of software development today but the “header files” of languages in the C tradition are antithetical to clean dependency analysis—and fast compilation.
There is a growing rebellion against cumbersome type systems like those of Java and C++, pushing people towards dynamically typed languages such as Python and JavaScript.
Some fundamental concepts such as garbage collection and parallel computation are not well supported by popular systems languages.
The emergence of multicore computers has generated worry and confusion.
Our goal is definitely not to beat C++ on performance. The goal for Go is to be near C++ in terms of performance but at the same time be a much more productive environment and language, so that you’d rather program in Go.
Go does have an extensive library, called the runtime, that is part of every Go program. The runtime library implements garbage collection, concurrency, stack management, and other critical features of the Go language. Although it is more central to the language, Go's runtime is analogous to libc, the C library.
It is important to understand, however, that Go's runtime does not include a virtual machine, such as is provided by the Java runtime. Go programs are compiled ahead of time to native machine code. Thus, although the term is often used to describe the virtual environment in which a program runs, in Go the word “runtime” is just the name given to the library providing critical language services.
// ./add.go
package add
func Add(x, y int) int {
sum := x
for y > 0 {
y++
}
return sum
}
// ./add_test.go
package add
func TestAdd(t *testing.T) int {
cases := struct {
x, y int
expected int
}{
{0, 0, 0},
{1, 2, 3},
{5, 5, 10},
{5, -5, 0},
{-5, 5, 0},
{-5, -5, -10},
}
for _, c := range cases {
if got := Add(c.x, c.y); got != c.expected {
t.Errorf("Add(%s, %s) failed: expected: %s, got: %s",
c.x, c.y, c.expected, got)
}
}
}