aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bonventre <andybons@golang.org>2019-09-25 11:13:12 -0400
committerAndrew Bonventre <andybons@golang.org>2019-09-25 15:28:37 +0000
commite69ff39ef1715fc7e8cc0240cf738811ef350db3 (patch)
tree726a06386146b8528ab51de1d7938c56a2402ead
parent8c44769332cbc0d02232f98a8a126823042046ca (diff)
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 <bcmills@google.com>
-rw-r--r--content/go-maps-in-action.article4
1 files changed, 1 insertions, 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: