Modern Go — 1.21 to 1.24 (2023–2025)
Go · History & Evolution · Run with go run
Explanation
Go 1.21 (August 2023) added the first built-in functions for slices and maps as top-level package functions — `slices.Sort`, `maps.Keys`, `maps.Values` — and introduced `log/slog` for structured logging. Go 1.22 (February 2024) fixed the infamous loop variable capture bug that had caused subtle goroutine closures to share the same variable. Go 1.23 (August 2024) shipped range-over-function iterators, letting custom container types be ranged over with a plain `for ... range`. Go 1.24 (February 2025) completed generics with generic type aliases, swapped the built-in map for a faster Swiss-table implementation, and added the `tool` directive to `go.mod` for tracking tool dependencies.
Real-World Scenario
The Go 1.22 loop variable fix (`for i, v := range slice` now creates a new `i` and `v` per iteration) eliminated a whole class of concurrent bugs where goroutines launched inside a for-range loop would all see the last value of the loop variable. The Go 1.23 iterator feature let libraries expose custom collections — trees, linked lists, paginated API results — through the same `for x := range collection` syntax that built-in slices and maps use.