Basics & Syntax
Go’s design philosophy
Section titled “Go’s design philosophy”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}What this module covers
Section titled “What this module covers”| Lesson | Topics |
|---|---|
| Packages & Imports | package, import, exported vs unexported identifiers |
| Variables & Types | var, :=, zero values, const, iota, type conversions |
| Control Flow | if with init, for (three forms), switch |
| Functions | Multiple 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.
Your first Go program
Section titled “Your first Go program”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)}Loading Go runtime (first run only, ~8 MB)…