Code that builds a report by looping over a map with for key, value := range someMap looks completely deterministic — same map, same keys, same values, every time. It isn't. Go deliberately randomizes the order a map is iterated in, and it changes from run to run of the exact same program. A test that happens to pass because the map came out in one particular order will flake the next time it runs, with no code change at all.
scores := map[string]int{"alice": 90, "bob": 85, "carol": 95}
var report string
for name, score := range scores { // map iteration order is randomized every run
report += fmt.Sprintf("%s:%d ", name, score)
}
fmt.Println(report)
// run 1: carol:95 alice:90 bob:85
// run 2: alice:90 bob:85 carol:95 -- same program, different orderGo’s standard library is unusually comprehensive for a systems language: net/http gives a production-grade web server, encoding/json handles serialization, testing covers unit tests and benchmarks, and crypto/* covers hashing and TLS — all without a third-party dependency. This is a deliberate design choice that reduces the surface area of supply-chain risk and version-conflict headaches common in ecosystems that lean more heavily on external packages.
Everyday packages: fmt, strings, strconv
fmt handles formatted I/O (Println, Sprintf, Errorf); strings covers string manipulation (splitting, joining, searching); strconv converts between strings and other types — these three appear in nearly every non-trivial Go file.
name := " Gopher "
trimmed := strings.TrimSpace(name) // "Gopher"
parts := strings.Split("a,b,c", ",") // ["a", "b", "c"]
n, err := strconv.Atoi("42") // 42, converts string to int
s := strconv.Itoa(42) // "42", converts int to string
msg := fmt.Sprintf("Hello, %s! You are %d.", trimmed, n)Collections and sorting: slices, maps, sort
Since Go 1.21, the generic slices and maps packages added common operations (slices.Sort, slices.Contains, maps.Keys) that previously required hand-written loops or the older, non-generic sort package interfaces.
nums := []int{5, 2, 8, 1}
slices.Sort(nums) // [1, 2, 5, 8], in place
fmt.Println(slices.Contains(nums, 8)) // trueThat same slices package is the fix for the randomized-map-order bug above: collect the keys into a slice, sort the slice, then iterate in that fixed order instead of ranging over the map directly.
scores := map[string]int{"alice": 90, "bob": 85, "carol": 95}
names := make([]string, 0, len(scores))
for name := range scores {
names = append(names, name)
}
slices.Sort(names) // deterministic order, every run
var report string
for _, name := range names {
report += fmt.Sprintf("%s:%d ", name, scores[name])
}
fmt.Println(report)
// every run: alice:90 bob:85 carol:95Time, networking, and cryptography
time handles durations, timestamps, and timers; net and net/http cover raw sockets up through full HTTP servers; crypto/sha256, crypto/tls, and related packages provide hashing and secure connections — all standard-issue, all without adding a dependency to go.mod.