Lesson 1 of 20 · Part 1: Getting started
Why learn Go?
What is Go (Golang), who uses it and why it is a great first or second programming language. Start the free beginner Go tutorial here.
6 min read · Updated · Beginner friendly
What you'll learn
- What Go is and why Google created it
- What Go is good at, and where it is used today
- What Go deliberately leaves out
- How this tutorial is organised and how to run the examples
Go (often called Golang, after its old website golang.org) is an open-source programming language made at Google. It is small enough to learn in a few weeks, fast enough to power some of the largest systems on the internet, and simple enough that code written by someone else is usually easy to read.
This lesson has no setup and only a little code. It explains what Go is so the rest of the tutorial makes sense.
A short history
In 2007, three engineers at Google (Robert Griesemer, Rob Pike and Ken Thompson) were frustrated. Building Google’s large C++ programs could take a long time, the code was hard to follow, and the languages they used were designed before multi-core processors and cloud servers were normal.
They set out to design a language that:
- compiles quickly, even for very large projects,
- is easy to read, so large teams can work on the same code,
- makes it natural to use many CPU cores and handle many network connections at once.
Go was released as open source in November 2009. Go 1.0 arrived in March 2012 with a promise that programs written for Go 1 would keep compiling with every later Go 1.x release. That promise still holds, which is one reason companies trust Go for long-lived software.
What makes Go different
It is small. Go has only 25 keywords. There is usually one obvious way to write something, so you spend less time choosing between styles and more time solving the problem.
It compiles to a single file. go build produces one executable with everything it needs. You can copy that file to a server and run it. No interpreter or virtual machine has to be installed first.
It is fast. Go compiles to machine code, so programs start instantly and run much faster than interpreted languages such as Python or JavaScript. The compiler itself is also very quick.
Memory is managed for you. A garbage collector frees memory you no longer use, so you do not call free by hand as you would in C.
Concurrency is built in. Running work at the same time is a core feature. A goroutine is a function running concurrently, and starting one is as easy as writing go doSomething(). Lessons 16 and 17 cover this.
The tools come in the box. Formatting (go fmt), testing (go test), documentation, dependency management and a race detector are all part of the standard go command.
A first taste of Go
You do not need to understand every line yet. Read it like a recipe and notice how little “noise” there is:
package main
import (
"fmt"
"strings"
)
func main() {
languages := []string{"Go", "Python", "JavaScript"}
for i, name := range languages {
fmt.Printf("%d. %s has %d letters\n", i+1, name, len(name))
}
fmt.Println(strings.ToUpper("go is fun!"))
}1. Go has 2 letters
2. Python has 6 letters
3. JavaScript has 10 letters
GO IS FUN!In one short program you can already see a list ([]string), a loop (for ... range), formatted printing (fmt.Printf) and a function from the standard library (strings.ToUpper). You will learn each of these properly in the coming lessons.
Try it now
Click Run in Playground on the code above. It copies the program and opens the official Go Playground, a free website that runs Go code in your browser. Paste the code, press Run, then change a word in the list and run it again.
Where Go is used
Go is especially popular for software that runs on servers and in the cloud. Many tools you may have heard of are written in Go:
| Project | What it does |
|---|---|
| Docker | Packages applications into containers |
| Kubernetes | Runs and scales containers across many machines |
| Terraform | Creates cloud infrastructure from configuration files |
| Prometheus | Collects and stores metrics for monitoring |
| Hugo | Generates static websites very quickly |
Companies such as Google, Uber, Cloudflare, Twitch and Dropbox use Go for APIs, back-end services and command-line tools. Go is a strong choice when you want to build:
- web servers and REST APIs,
- command-line tools (one binary, easy to share),
- cloud and DevOps tooling,
- programs that handle lots of work at the same time, such as crawlers, queues and chat servers.
Go is a less common choice for desktop GUIs, mobile apps or data science, where other ecosystems have more libraries.
What Go leaves out, on purpose
If you know another language, some missing features may surprise you. They were left out to keep the language simple:
- No classes or inheritance. You define your own types with structs and add behaviour with methods. Code is reused by composition instead of inheritance (lessons 8 and 12).
- No exceptions. Functions that can fail return an
errorvalue that you check, so the failure path is always visible in the code (lesson 11). - No ternary operator (
a ? b : c). You write a normalifinstead. - No unused imports or variables. The compiler refuses to build code that has them. It feels strict at first, but it keeps code clean.
Good to know
Generics (writing one function that works for many types) were added in Go 1.18 in 2022. Some older books and blog posts say Go has no generics. That is no longer true, and lesson 14 covers them.
Go compared with other languages
A rough comparison to help you place Go:
| Go | Python | Java | |
|---|---|---|---|
| Typing | Static (checked when compiling) | Dynamic (checked when running) | Static |
| Runs as | Native machine code | Interpreted | JVM bytecode |
| Speed | Fast | Slower | Fast |
| Deploying | One executable file | Needs Python + packages | Needs a JVM |
| Concurrency | Goroutines and channels, built in | Threads, asyncio |
Threads, virtual threads |
| Learning curve | Gentle | Gentle | Steeper |
There is no single “best” language. Go shines when you want simple code that runs fast and is easy to deploy.
How this tutorial works
The tutorial has 20 lessons in 6 parts. Each lesson builds on the previous one, so it is best to follow them in order. Every lesson has:
- What you’ll learn: a short list at the top.
- Explanations with small examples. Each runnable example shows its exact output underneath.
- Common mistakes: traps that catch most beginners.
- Exercises with hidden solutions, so you can practise before you peek.
Every full program in this tutorial has been compiled and run with a current version of Go, so the output you see is the real output.
You can run the examples in two ways:
- In your browser with the Run in Playground button. Nothing to install.
- On your computer, which the next lesson shows you how to set up. This is what you will want for real projects.
Exercise
Make it yours. Open the “first taste” program in the Go Playground. Add your favourite language to the list and change the last line to print a different message in upper case.
Show solution
package main
import (
"fmt"
"strings"
)
func main() {
languages := []string{"Go", "Python", "JavaScript", "Rust"}
for i, name := range languages {
fmt.Printf("%d. %s has %d letters\n", i+1, name, len(name))
}
fmt.Println(strings.ToUpper("i am learning go"))
}1. Go has 2 letters
2. Python has 6 letters
3. JavaScript has 10 letters
4. Rust has 4 letters
I AM LEARNING GORecap
- Go is a small, fast, compiled language created at Google and released in 2009.
- It builds a single executable, manages memory for you and has concurrency built in.
- It is widely used for cloud tools, web services and command-line programs.
- It leaves out classes, exceptions and other features on purpose to stay simple.
In the next lesson you will install Go and write your first program on your own computer.
Finished this lesson?
Your progress is saved in this browser only.