Reading — step 1 of 5
Learn
Hello, World
Every Go program you will ever write — from this one to a production load balancer — has the same skeleton. Learn it once, precisely, and nothing in the language will ever look unfamiliar:
Four pieces, each load-bearing:
package main— every Go file belongs to a package. The package namedmainis special: it means "this compiles to a runnable program" (as opposed to a library other code imports).import "fmt"— brings in the format package from the standard library. Go's stdlib is famously batteries-included: HTTP servers, JSON, crypto — you'll rarely leave it in this course.func main()— the entry point. When your program runs, execution starts at the first line of this exact function and the program exits when it returns.fmt.Println(...)— print the arguments, then a newline. The capital P matters: in Go, capitalized names are public (usable from other packages), lowercase names are private. That's not a convention — it's the language's entire visibility system, in one letter.
Run it
$ go run main.go # compile + run in one step (development)
Hello, World
$ go build main.go # produce a binary
$ ./main
Hello, World
That main binary is worth pausing on, because it's Go's core pitch: a single, self-contained, native executable. No interpreter to install, no virtual machine to warm up, no node_modules to ship. Copy the file to any machine with the same OS/architecture and it runs. This property — plus compile times fast enough to feel like a scripting language — is why Docker, Kubernetes, Terraform, and half of modern infrastructure are written in Go.
The compiler has opinions
Try adding an import you don't use, or declaring a variable you never read:
These are compile errors, not warnings. Go refuses to build code with dead imports and dead variables, ever. It feels strict on day one; by week two you'll notice every Go codebase on earth is free of the import-graveyard that tops most files in other languages. The same philosophy powers gofmt — the official formatter that ends all bracket-style debates by having exactly one style. Run gofmt -w . (or let your editor do it on save); in the Go world, unformatted code simply doesn't get past code review.
One trap before the exercise
The exercise asks you to print exact output — and graders compare byte for byte. Two things bite beginners:
fmt.Println("x")appends the newline for you;fmt.Print("x")doesn't. Doubling up (fmt.Println("x\n")) produces a blank line that fails tests.- Capitalization and punctuation must match exactly.
hello, world≠Hello, World.
Type the program out by hand rather than pasting — your fingers are learning the skeleton you'll use ten thousand more times.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…