GO LEARNING PATH · 16 LESSONS
Slices, maps and strings
Length against capacity, shared backing arrays, and why a string is not a []char.
A slice is a window, not a copied array
Predict a subslice, an element write and append by tracking the backing array.
3 min · Worked lesson
len is what you have, cap is what you can grow into
Predict when append allocates and when it writes in place.
3 min · Prediction challenge
Two slices, one array
Spot the moment a subslice starts sharing writes with its parent.
3 min · Worked lesson
Shared slices and concurrent append
Separate shared headers, shared elements and safe collection of concurrent results.
3 min · Worked lesson
Reading a missing key is fine, writing to a nil map is not
Use comma-ok, and know which map operation panics.
3 min · Worked lesson
A string is bytes; range gives you runes
Index, slice and iterate a string without corrupting characters.
3 min · Prediction challenge
range works on functions too
Write something that can be ranged over without building a slice first.
3 min · Worked lesson
len is what you may read; cap is what you may reslice
Say which of two similar-looking index expressions panics.
3 min · Prediction challenge
A tiny slice can keep a large buffer alive
Recognize retained backing arrays and detach small long-lived results deliberately.
3 min · Worked lesson
Map iteration order is not specified
Produce stable output from a map without hoping.
3 min · Worked lesson
Concatenating in a loop repeatedly rebuilds a string
Use strings.Builder for repeated construction without rebuilding the prefix.
3 min · Worked lesson
make builds the header; new only allocates
Pick make or new for a slice, a map and a pointer.
3 min · Worked lesson
The length is part of an array's type
Write a function that takes [4]int and returns [3]int.
3 min · Worked lesson
Comma-ok is how you tell zero from missing
Report whether a key is present when its value can be zero.
3 min · Worked lesson
A nil slice is empty, and append still works
Predict what len, == nil and append do to a zero slice.
3 min · Prediction challenge
A function is a value you can pass
Apply a func(int) int to every element of a slice.
3 min · Worked lesson