]> Cypherpunks repositories - gostls13.git/commitdiff
doc: sort map output in Effective Go
authorRob Pike <r@golang.org>
Wed, 6 Mar 2019 00:56:06 +0000 (11:56 +1100)
committerRob Pike <r@golang.org>
Wed, 6 Mar 2019 03:51:21 +0000 (03:51 +0000)
And explain that it does this. A minor change probably worth mentioning,
although (#28782) I'd still like to freeze this document against any substantial
changes.

Fix #30568.

Change-Id: I74c56744871cfaf00dc52a9b480ca61d3ed19a6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/165597
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
doc/effective_go.html

index 34131868a4c751a70f6add6353c6753889b016b1..b98235931c30ac29e3531e44952040d796c304a6 100644 (file)
@@ -1680,13 +1680,13 @@ maps.  Here is a print statement for the time zone map defined in the previous s
 fmt.Printf("%v\n", timeZone)  // or just fmt.Println(timeZone)
 </pre>
 <p>
-which gives output
+which gives output:
 </p>
 <pre>
-map[CST:-21600 PST:-28800 EST:-18000 UTC:0 MST:-25200]
+map[CST:-21600 EST:-18000 MST:-25200 PST:-28800 UTC:0]
 </pre>
 <p>
-For maps the keys may be output in any order, of course.
+For maps, <code>Printf</code> and friends sort the output lexicographically by key.
 When printing a struct, the modified format <code>%+v</code> annotates the
 fields of the structure with their names, and for any value the alternate
 format <code>%#v</code> prints the value in full Go syntax.
@@ -1710,7 +1710,7 @@ prints
 &amp;{7 -2.35 abc   def}
 &amp;{a:7 b:-2.35 c:abc     def}
 &amp;main.T{a:7, b:-2.35, c:"abc\tdef"}
-map[string]int{"CST":-21600, "PST":-28800, "EST":-18000, "UTC":0, "MST":-25200}
+map[string]int{"CST":-21600, "EST":-18000, "MST":-25200, "PST":-28800, "UTC":0}
 </pre>
 <p>
 (Note the ampersands.)