The problem Go was built to solve
In the late 2000s, Google's engineers had massive C++ codebases that took tens of minutes to compile. The language was complex enough that even experienced engineers disagreed on how to write it well, and the tools struggled to keep up.
In 2007, three engineers, Robert Griesemer, Rob Pike and Ken Thompson, started sketching ideas for a new language. Pike and Thompson had worked together at Bell Labs on Unix and Plan 9. Thompson co-created the C language and co-authored the first Unix. Griesemer had worked on the V8 JavaScript engine and the Sawzall language at Google. All three had built systems software before they set out to design a language for it.
The legend of Go's creation
The story goes that Go was conceived while waiting for a C++ build to finish. It sounds like a joke, but slow compilation was a real cost to productivity, and one of Go's earliest design goals was that a large program should build in seconds instead of minutes.
Go 1.0 was released in March 2012, and it has kept backwards compatibility ever since: code you write today will still compile on future versions of Go.
What Go is
Go is a statically typed, compiled, garbage-collected language with concurrency built into it. Each of those terms says something specific about how you work with it.
Statically typed means the type of every variable is known at compile time. The compiler catches type errors before your program ever runs. C, C++ and Java use the same model, while Python and JavaScript check types at runtime.
Compiled means your Go source code is translated directly into machine code that runs on the processor. There is no virtual machine, interpreter or bytecode layer. The result is a single native binary that runs fast and starts almost immediately.
Garbage collected means you do not manage memory manually. You do not call malloc and free. Go's runtime tracks which objects are still in use and reclaims memory that is no longer reachable. That removes whole categories of bugs that plague C and C++ programs, such as buffer overflows, use-after-free and double-free.
Concurrent by design means the language has first-class primitives for running work concurrently. Goroutines are lightweight functions that start with go and cost only a few kilobytes of stack, so you can run thousands of them in a single process. Channels are typed conduits through which goroutines communicate, replacing shared memory and locks with message passing. This model comes from Tony Hoare's Communicating Sequential Processes (CSP), a formal framework for concurrent programs.
The best of both worlds
Go sits in an unusual spot: it gives you the performance of a compiled language and the safety of a managed runtime. C++ is fast but demands manual memory management. Python is safe but slow and interpreted. Go was designed so you get speed and safety in the same language.
Standing on the shoulders of giants
Go's designers deliberately drew from several earlier languages and ideas.
From C
Go's syntax is clearly C-inspired. Curly braces, for loops, pointers, functions and structs will feel familiar to anyone who has written C. Go leaves out the parts of C that cause the most trouble: there is no pointer arithmetic, no header files and no undefined behavior from uninitialized memory.
From CSP
The most distinctive part of Go's concurrency model comes from a 1978 academic paper, Communicating Sequential Processes (CSP) by Tony Hoare. In CSP, independent processes communicate by passing messages through channels instead of sharing memory and using locks.
Go made this practical. Goroutines are lightweight functions that run concurrently, and channels are typed conduits through which they communicate. You will explore both in depth later in this series.
go doSomething() // launch a goroutineresult := <-myChannel // receive from a channelFrom other influences
The package system and module model draw from languages like Oberon and Modula. The interface system, structural typing without explicit declaration, has roots in duck typing. Go's designers kept the pieces that worked and discarded the rest.
The core design philosophy
Go keeps the language small and tries to make each part of it work well.
- Few keywords: Go has 25 reserved keywords. C has 32. C++ has over 80. Fewer keywords means less to memorize and more consistent codebases.
- One way to do things: Go deliberately avoids offering several ways to express the same idea. Code written by different people ends up looking similar, which matters at scale.
- Fast compilation: A large Go program compiles in seconds, so you iterate and catch errors faster.
- Explicit over implicit: Go code does what it says. There are no hidden constructors, no operator overloading and no implicit conversions.
Your first Go program
Every Go program starts with a package declaration. The main package is special because it defines an executable program, and the main function inside it is the entry point.
package mainimport "fmt"func main() { fmt.Println("Hello, World!")}Line by line:
package main: declares that this file belongs to themainpackageimport "fmt": imports the standard library package for formatted I/Ofunc main(): the function Go calls when the program startsfmt.Println: prints a line to standard output
To run it:
go run main.goTo compile it into a standalone binary:
go build main.go./maingo run compiles and runs in one step, which is handy during development. go build produces a binary you can distribute and deploy without any Go toolchain installed on the target machine.
Summary
- Griesemer, Pike and Thompson started designing Go at Google in 2007, frustrated by slow C++ builds and an overly complex language. Go 1.0 came out in March 2012 and has stayed backwards compatible since.
- Go is statically typed, compiled to a native binary, garbage collected, and has goroutines and channels for concurrency.
- Its syntax comes from C, its concurrency model from Hoare's CSP, and its package system from Oberon and Modula.
- The language is deliberately small: 25 keywords, one way to do most things, fast compilation and no implicit behavior.
go runcompiles and runs a program in one step;go buildproduces a binary that runs without the Go toolchain.