Commit c7408a87 authored by Rob Pike's avatar Rob Pike

doc: sort map output in Effective Go

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/+/165597Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e90f572c
...@@ -1680,13 +1680,13 @@ maps. Here is a print statement for the time zone map defined in the previous s ...@@ -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) fmt.Printf("%v\n", timeZone) // or just fmt.Println(timeZone)
</pre> </pre>
<p> <p>
which gives output which gives output:
</p> </p>
<pre> <pre>
map[CST:-21600 PST:-28800 EST:-18000 UTC:0 MST:-25200] map[CST:-21600 EST:-18000 MST:-25200 PST:-28800 UTC:0]
</pre> </pre>
<p> <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 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 fields of the structure with their names, and for any value the alternate
format <code>%#v</code> prints the value in full Go syntax. format <code>%#v</code> prints the value in full Go syntax.
...@@ -1710,7 +1710,7 @@ prints ...@@ -1710,7 +1710,7 @@ prints
&amp;{7 -2.35 abc def} &amp;{7 -2.35 abc def}
&amp;{a:7 b:-2.35 c:abc def} &amp;{a:7 b:-2.35 c:abc def}
&amp;main.T{a:7, b:-2.35, c:"abc\tdef"} &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> </pre>
<p> <p>
(Note the ampersands.) (Note the ampersands.)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment