← Course map

GO LEARNING PATH · 16 LESSONS

Slices, maps and strings

Length against capacity, shared backing arrays, and why a string is not a []char.

  1. 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

  2. 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

  3. Two slices, one array

    Spot the moment a subslice starts sharing writes with its parent.

    3 min · Worked lesson

  4. Shared slices and concurrent append

    Separate shared headers, shared elements and safe collection of concurrent results.

    3 min · Worked lesson

  5. 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

  6. A string is bytes; range gives you runes

    Index, slice and iterate a string without corrupting characters.

    3 min · Prediction challenge

  7. range works on functions too

    Write something that can be ranged over without building a slice first.

    3 min · Worked lesson

  8. 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

  9. A tiny slice can keep a large buffer alive

    Recognize retained backing arrays and detach small long-lived results deliberately.

    3 min · Worked lesson

  10. Map iteration order is not specified

    Produce stable output from a map without hoping.

    3 min · Worked lesson

  11. Concatenating in a loop repeatedly rebuilds a string

    Use strings.Builder for repeated construction without rebuilding the prefix.

    3 min · Worked lesson

  12. make builds the header; new only allocates

    Pick make or new for a slice, a map and a pointer.

    3 min · Worked lesson

  13. The length is part of an array's type

    Write a function that takes [4]int and returns [3]int.

    3 min · Worked lesson

  14. 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

  15. A nil slice is empty, and append still works

    Predict what len, == nil and append do to a zero slice.

    3 min · Prediction challenge

  16. A function is a value you can pass

    Apply a func(int) int to every element of a slice.

    3 min · Worked lesson