From: Rob Pike Date: Wed, 11 May 2011 15:31:24 +0000 (-0700) Subject: effective go: explain about values/pointers in String() example X-Git-Tag: weekly.2011-05-22~113 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=89c59bc6f6bb8af66e8fb290c57081a18000f9cf;p=gostls13.git effective go: explain about values/pointers in String() example Fixes #1796. R=rsc, r2, niemeyer CC=golang-dev https://golang.org/cl/4539049 --- diff --git a/doc/effective_go.html b/doc/effective_go.html index 1aeed4ad84..86b2d63dcb 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -1489,6 +1489,12 @@ to print in the format 7/-2.35/"abc\tdef"

+(If you need to print values of type T as well as pointers to T, +the receiver for String must be of value type; this example used a pointer because +that's more efficient and idiomatic for struct types. +See the section below on pointers vs. value receivers for more information.) +

+

Our String() method is able to call Sprintf because the print routines are fully reentrant and can be used recursively. We can even go one step further and pass a print routine's arguments directly to another such routine.