Hi folks, It seems to me that the reasons given for why you need to use the return value of append() are confusing and not quite right. For example, at https://blog.golang.org/slices#TOC_9. Rob Pike says:
"In this case it's especially important to return the slice, since when it reallocates the resulting slice describes a completely different array." But (if I understand correctly) you need to return the slice *every* time, not because the slice reallocates, but because the slice is passed by value, so no changes to the length will be reflected to the caller unless you return the new slice. It doesn't matter whether or not the underlying array has changed or been reallocated. In Effective Go under "Slices" (https://golang.org/doc/effective_go.html#slices) it gives the correct reason first, just under the definition of `func Append...`: "We must return the slice afterwards because ... the slice itself (the run-time data structure holding the pointer, length, and capacity) is passed by value." But then when it's actually talking about the built-in append() a bit lower down it gives the more confusing reason again: "The result needs to be returned because, as with our hand-written Append, the underlying array may change." Is there any further context or historical reason why Rob Pike would have said it like that in his blog entry, and why Effective Go says the same thing in one place? Were slices previously passed implicitly by reference, kind of like maps are? Assuming I'm not the one confused here (and I am a Go newbie), should I suggest a wording update to the blog entry and Effective Go to avoid this confusion? -Ben -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.