Skip to content

Basics & Syntax

Go was designed around three ideas that shape everything you write in it.

Simplicity over cleverness. The language has a small spec. There is deliberately no overloading, no default arguments, no implicit conversions, and no inheritance. When you read Go code written by someone else, it looks almost exactly like code you would have written yourself — that is intentional.

Explicit over implicit. Type conversions, error handling, and memory allocation are all visible at the call site. Nothing happens behind the scenes that you have not written. This makes the code easy to trace and audit.

One obvious way. Go’s tooling enforces a single code style (gofmt), a single module system (go mod), and a single test runner (go test). Debates about formatting, import order, and project layout simply do not happen.

// The compiler rejects unused imports and unused local variables.
// This keeps every file minimal and every dependency intentional.
import "fmt"
func greet(name string) string {
return "Hello, " + name
}
LessonTopics
Packages & Importspackage, import, exported vs unexported identifiers
Variables & Typesvar, :=, zero values, const, iota, type conversions
Control Flowif with init, for (three forms), switch
FunctionsMultiple returns, defer, closures, first-class functions

By the end of this module you will be able to read and write complete idiomatic Go programs from scratch.

Every executable Go program lives in package main and execution starts in func main. Here is a program that prints a greeting and shows a few basic values:

package main
import "fmt"
func main() {
name := "Go"
version := 1.22
fast := true
fmt.Println("Hello from", name)
fmt.Println("Version:", version)
fmt.Println("Fast compile:", fast)
}

Run it below to see the output. Every concept used here — short variable declaration, basic types, fmt.Println — is covered in detail in the lessons that follow.

package main
import "fmt"
func main() {
name := "Go"
version := 1.22
fast := true
fmt.Println("Hello from", name)
fmt.Println("Version:", version)
fmt.Println("Fast compile:", fast)
// Integer arithmetic is exact; no implicit float promotion
a := 10
b := 3
fmt.Println("10 / 3 =", a/b)
fmt.Println("10 % 3 =", a%b)
}
Which of the following does Go enforce at compile time to keep code minimal?
What is the entry point of every executable Go program?
What does Go's single-style enforcement mean in practice?