From e69ff39ef1715fc7e8cc0240cf738811ef350db3 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 25 Sep 2019 11:13:12 -0400 Subject: content/go-maps-in-action: remove line about random iteration order This article is cited as a source of confusion on whether map iteration is "random", something that is objectively correct because woefully underdefined, but that some have assumed to mean "uniformly random" - which is not: - https://twitter.com/wallyqs/status/1135719212024909824 - https://twitter.com/ultimateboy/status/1135325432624975872 Based on golang.org/cl/180457 by Carlo Alberto Ferraris Change-Id: I2b75bc1ce592502fc1ddeb941a5a258dcb1925a1 Reviewed-on: https://go-review.googlesource.com/c/blog/+/197238 Reviewed-by: Bryan C. Mills --- content/go-maps-in-action.article | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/content/go-maps-in-action.article b/content/go-maps-in-action.article index 7cca838..cc6d62c 100644 --- a/content/go-maps-in-action.article +++ b/content/go-maps-in-action.article @@ -156,7 +156,7 @@ This statement declares a `counter` variable that is an anonymous struct contain To read from the counter, take the read lock: - + counter.RLock() n := counter.m["some_key"] counter.RUnlock() @@ -171,8 +171,6 @@ 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 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: -- cgit v1.2.3