Introduction
What you will learn
This lesson answers three questions. What is Go? Why was it built? When should you pick it over something else? Along the way you will meet two terms you will hear constantly, compiled and statically typed, through a real bug that Go stops before it can reach a user.
A bug Go refuses to run
Here is a small Python function that calculates a price:
def total(price, quantity):
return price * quantity
print(total("5", 3)) # prints 555
Someone passed the price as a string, "5", instead of a number. Python does not complain. It repeats the string three times and prints 555. The program keeps running with a wrong answer, and you may not notice until a customer is charged 555 instead of 15.
Now the same idea in Go:
package main
import "fmt"
func total(price int, quantity int) int {
return price * quantity
}
func main() {
fmt.Println(total("5", 3))
}
Go refuses to build this program:
cannot use "5" (untyped string constant) as int value in argument to total
The mistake is caught on your machine, in seconds, with the file and line number. That single behaviour is the heart of why many teams choose Go, and the rest of this lesson explains where it comes from.
Where Go came from
Go was designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Work started in 2007, the language was announced in 2009, and Go 1.0 shipped in 2012.
The problem they faced was practical. Google had huge C++ and Java codebases, builds that took many minutes, languages with a lot of features to remember, and servers that had to handle thousands of connections at once. They wanted a language that was fast to compile, simple to read, safe enough to trust, and built for networked programs doing many things at the same time.
Everything in Go follows from those goals, including the things that may feel missing at first.
What "compiled" means
Computers cannot run source code directly. Something has to translate it into instructions the processor understands. Languages differ in when and how that happens.
| Python | Java | Go | |
|---|---|---|---|
| How code runs | Read and executed by an interpreter | Compiled to bytecode, run by the JVM | Compiled straight to machine code |
| What you ship | Source files plus a Python install and packages | .jar files plus a Java runtime | One executable file |
| When many mistakes appear | When that line runs | At compile time | At compile time |
In Go the flow looks like this:
main.go → go build → executable file → you run it
The compiler reads every file, checks it, and produces an executable. If the check fails, no executable is produced. That is why the total("5", 3) bug above never reaches a user.
What "statically typed" means
A type says what kind of value something is, such as int for whole numbers, float64 for decimals, string for text, and bool for true or false. Statically typed means every value has a type that is fixed and known before the program runs, and the compiler checks that the types fit together.
age := 25 // Go infers that age is an int
age = "twenty-five" // compile error: cannot use a string as an int
The := symbol declares a new variable and lets Go work out its type from the value. After that, age is an int forever. You will meet this properly in the variables lesson, so do not worry about memorising it yet.
Why does this matter? Because the alternative is finding type mistakes in production. A static type system turns a whole category of runtime bugs into compile-time errors, which are far cheaper to fix.
Why developers choose Go
Fast feedback
Go compiles quickly, even for large projects. You change a file, run go run ., and see the result almost immediately. This keeps the edit-and-test loop short, which makes learning and daily work more pleasant.
Code that looks the same everywhere
Go ships with a formatter, gofmt, and the whole community uses it. Tabs versus spaces and brace placement are not up for debate. When you open an unfamiliar Go project, it reads like code you wrote.
Easy deployment
A pure-Go program builds to a single executable with no runtime to install. You can even build for another operating system from your own machine:
GOOS=linux GOARCH=amd64 go build -o server .
Copy server to a Linux machine and run it. There is no interpreter to install and no dependency folder to carry along. (Programs that use C libraries or certain platform features can have extra requirements, but plain Go does not.)
Built-in support for doing many things at once
Go has goroutines, which are very cheap units of concurrent work. Starting one takes a single keyword:
go fetchPage(url)
You do not need to understand this yet. Just notice that it is a core part of the language, not a library bolted on.
A common misunderstanding is that goroutines make a program faster. They do not make one calculation faster. What they do is let a program overlap waiting time. Imagine checking 100 websites that each take 200 ms to respond. One after another, that is 20 seconds. With goroutines, all 100 requests wait at the same time and the total is close to 200 ms.
Goroutines also do not remove the need for careful design. Someone still has to decide who owns each piece of data and when a task should stop. You will learn that properly in the concurrency stage.
A useful standard library
Go includes HTTP clients and servers, JSON, file handling, cryptography, time, logging, and a testing framework. For many programs you will not need any third-party package at all.
Garbage collection
Go automatically frees memory that your program no longer uses, so you do not call free yourself. This does not close files for you, stop goroutines, or stop you from holding onto data you no longer need. It only reclaims memory that nothing can reach any more.
Where Go is used
| Tool | What it does |
|---|---|
| Docker | Packages and runs applications in containers |
| Kubernetes | Manages containers across many machines |
| Terraform | Describes cloud infrastructure as code |
| Prometheus | Collects metrics for monitoring |
GitHub CLI (gh) | Controls GitHub from the terminal |
These share a pattern: network-heavy, long-running programs or command-line tools that need to be fast, reliable, and easy to install. Go is also common for backend APIs and data-processing workers.
Go is a weaker fit for some work. Desktop and mobile user interfaces, data science, and machine learning mostly live in other ecosystems with far more libraries. A throwaway ten-line script is often quicker in Python. Choosing Go for a project means choosing it because its strengths match the problem, not because it is popular.
Go's trade-offs
Every design choice that makes Go simple also takes something away.
Errors are explicit. Go has no exceptions. Functions that can fail return an error, and you check it:
data, err := os.ReadFile("notes.txt")
if err != nil {
return err
}
This is more typing than a try/catch, but every place that can fail is visible in the code. You will write this pattern thousands of times.
The language is deliberately small. Go has no classes or inheritance, and for a long time had no generics. Generics arrived in Go 1.18, but they are intentionally limited. Some programmers find this restrictive, while others find it makes code easier to read and review.
Garbage collection has a cost. Pauses are usually tiny, but extremely latency-sensitive systems may need to account for them.
Concurrency is easy to start and easy to misuse. Careless use can create data races and deadlocks.
Learning these trade-offs is part of learning Go well.
Go or Golang?
The language is officially called Go. People write "Golang" because go is a very common English word that is hard to search for, and the original website lived at golang.org. Searching for "golang" often finds better results, but the name is Go.
Check your understanding
Try to answer these in your own words before opening the answers.
- What work does the compiler do for you?
- What is the difference between a goroutine and "automatic speed"?
- Why does a small language still need careful design?
- It translates your source code into an executable and checks that types and imports fit together. If the check fails, no executable is produced.
- A goroutine lets work overlap, mainly while waiting on networks or disks. It does not make a single calculation faster, and you must still design who owns data and when tasks stop.
- A small language removes features, not problems. You still need to structure code, handle errors, and decide how pieces share data. The language just offers fewer ways to express each idea.
Practice
Read this program and decide which lines will not compile. Explain why.
package main
import "fmt"
func main() {
count := 10
count = "ten"
var ok bool = 1
fmt.Println(count, ok)
}
count := 10 is fine. Go infers that count is an int.
count = "ten" fails because a string cannot be assigned to an int variable:
cannot use "ten" (untyped string constant) as int value in assignment
var ok bool = 1 fails because 1 is a number and a bool only accepts true or false:
cannot use 1 (untyped int constant) as bool value in variable declaration
Go does not convert between these types for you, which is the same protection that rejected total("5", 3) earlier. The compiler found both mistakes before the program ran.
Summary
Go is a compiled, statically typed, garbage-collected language created at Google to make large networked software easier to build and maintain. Compilation produces a single executable and catches many mistakes early. Its strengths are fast builds, consistent formatting, easy deployment, built-in concurrency, and a strong standard library. Its trade-offs are explicit error handling, a deliberately small feature set, and the need to design concurrent code carefully.
Official reference: The Go language specification.
Ready to wrap up?
Mark this complete when you can explain the main idea and finish the practice task.