diff options
-rw-r--r-- | content/go-maps-in-action.article | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/content/go-maps-in-action.article b/content/go-maps-in-action.article index e57edc6..7cca838 100644 --- a/content/go-maps-in-action.article +++ b/content/go-maps-in-action.article @@ -170,7 +170,11 @@ To write to the counter, take the write lock: * Iteration order -When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next. Since Go 1 the runtime randomizes map iteration order, as programmers relied on the stable iteration order of the previous implementation. If you require a stable iteration order you must maintain a separate data structure that specifies that order. This example uses a separate sorted slice of keys to print a `map[int]string` in key order: +When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next. +Since the release of Go 1.0, the runtime has randomized map iteration order. +Programmers had begun to rely on the stable iteration order of early versions of Go, which varied between implementations, leading to portability bugs. +If you require a stable iteration order you must maintain a separate data structure that specifies that order. +This example uses a separate sorted slice of keys to print a `map[int]string` in key order: import "sort" |