Go
In short
Go is a compiled, statically typed language built for simplicity and fast builds, with garbage collection and built-in concurrency through goroutines.
What is the Go programming language?
Go is an open-source programming language created at Google by Robert Griesemer, Rob Pike, and Ken Thompson and released in 2009. It is often called "Golang" after its original website address, a name that is also easier to search for. Go was designed to keep large codebases easy to read and maintain, with a small set of keywords, one standard formatting tool (gofmt), and fast compilation to a single self-contained executable.
Go is statically typed, and short declarations like count := 5 let the compiler infer types. A type satisfies an interface simply by having the right methods, without declaring it, and generics have been available since Go 1.18. Memory is garbage-collected, but Go also has pointers (without pointer arithmetic) and value types, which give developers some control over how memory is laid out. Errors are ordinary values returned from functions rather than exceptions, so code typically checks if err != nil after each call that can fail.
Go's signature feature is built-in concurrency. A goroutine, started with the go keyword, is a lightweight function that runs at the same time as others, and channels let goroutines pass values to each other safely. It's like cooks in a kitchen handing finished dishes through a serving window instead of all grabbing from the same shelf. This makes Go popular for cloud infrastructure, network services, microservices, and command-line tools, including widely used container tools such as Docker and Kubernetes.
A goroutine is not the same as an operating system thread. The Go runtime schedules many goroutines onto a smaller pool of OS threads, so a goroutine starts with only a few kilobytes of stack and a program can run hundreds of thousands of them. OS threads are heavier to create and switch between, which is why Go programs can handle many concurrent connections with modest resources.
Key takeaways
- Go compiles to a single native executable with no separate runtime to install.
- It is statically typed and garbage-collected, with a deliberately small feature set.
- Goroutines and channels make concurrent programs simpler to write.
- Errors are returned as values instead of being thrown as exceptions.
- It is popular for cloud services, networking tools, and command-line programs.
Example
package main
import "fmt"
func main() {
results := make(chan string)
for i := 1; i <= 3; i++ {
// Each goroutine runs concurrently and sends a message
go func(id int) { results <- fmt.Sprintf("worker %d done", id) }(i)
}
for i := 0; i < 3; i++ {
fmt.Println(<-results) // Receive one message from the channel
}
}Readers ask
Why is Go also called Golang?
The language's official name is Go, but its original website was golang.org, and "golang" is easier to search for than the common word "go". Both names refer to the same language.
Does Go have classes?
No. Go uses structs to group data and lets you attach methods to any type you define, and it relies on interfaces and composition instead of class inheritance.
Is Go garbage-collected?
Yes. Go has a concurrent garbage collector designed for short pauses, so developers don't free memory manually, though they can still use pointers and value types to reduce allocations.
Often compared
See also
- ConcurrencyProgramming Fundamentals, p. 12Concurrency is a program's ability to make progress on several tasks in overlapping time periods, such as serving many users at once rather than one at a time.
- ThreadOperating Systems, p. 33A thread is the smallest unit of execution an operating system can schedule, running inside a process and sharing that process's memory with other threads.
- Garbage CollectionProgramming Fundamentals, p. 23Garbage collection is automatic memory management in which the language runtime finds data a program can no longer use and frees that memory for reuse.
- InterfaceProgramming Fundamentals, p. 29An interface is a named set of method and property signatures that a type promises to provide, without saying how those members are implemented.
- MicroservicesSoftware Architecture, p. 27Microservices are an architectural style where an application is split into small, independently deployable services that communicate over a network.
- DockerDevOps & Cloud, p. 17Docker is an open-source platform for packaging an application and everything it needs into a container that runs the same way on any machine.
Spotted a mistake or something missing on this page?Suggest an edit