content: clarify append code example
Rename variable: a (array) -> s (slice).
Capitalize comments to make full sentences.
Simplify printSlice function. There's no need to pass a
descriptive string, since the name of the slice is the same
each time the function is called.
Change-Id: I18981b4c649ee84b121f3aedce5ee62c2fa37b08
Reviewed-on: https://go-review.googlesource.com/19404
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/content/moretypes/append.go b/content/moretypes/append.go
index 675cf52..f13b9d6 100644
--- a/content/moretypes/append.go
+++ b/content/moretypes/append.go
@@ -5,23 +5,22 @@
import "fmt"
func main() {
- var a []int
- printSlice("a", a)
+ var s []int
+ printSlice(s)
// append works on nil slices.
- a = append(a, 0)
- printSlice("a", a)
+ s = append(s, 0)
+ printSlice(s)
- // the slice grows as needed.
- a = append(a, 1)
- printSlice("a", a)
+ // The slice grows as needed.
+ s = append(s, 1)
+ printSlice(s)
- // we can add more than one element at a time.
- a = append(a, 2, 3, 4)
- printSlice("a", a)
+ // We can add more than one element at a time.
+ s = append(s, 2, 3, 4)
+ printSlice(s)
}
-func printSlice(s string, x []int) {
- fmt.Printf("%s len=%d cap=%d %v\n",
- s, len(x), cap(x), x)
+func printSlice(s []int) {
+ fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}