diff options
author | Rob Pike <r@golang.org> | 2009-12-25 07:13:14 +1100 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-12-25 07:13:14 +1100 |
commit | 9edc0018997afda85492864349c62b761a88e52d (patch) | |
tree | d92c916f59f9c053c0c4674501a8f936a1641e00 | |
parent | 939a5dad22b2ca59762c2b33911900fdcd407bf1 (diff) | |
download | go-9edc0018997afda85492864349c62b761a88e52d.tar.gz |
fix naked < and > as reported by Peter Williams <>
(i thought these were legal in <pre> blocks)
R=rsc
CC=golang-dev, pwil3058
http://codereview.appspot.com/181055
-rw-r--r-- | doc/effective_go.html | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/doc/effective_go.html b/doc/effective_go.html index c9f1a1257..293270950 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -405,7 +405,7 @@ effects. Write them like this </p> <pre> -if i < f() { +if i < f() { g() } </pre> @@ -413,7 +413,7 @@ if i < f() { not like this </p> <pre> -if i < f() // wrong! +if i < f() // wrong! { // wrong! g() } @@ -444,7 +444,7 @@ and the bodies must always be brace-delimited. In Go a simple <code>if</code> looks like this: </p> <pre> -if x > 0 { +if x > 0 { return y } </pre> @@ -529,7 +529,7 @@ Short declarations make it easy to declare the index variable right in the loop. </p> <pre> sum := 0 -for i := 0; i < 10; i++ { +for i := 0; i < 10; i++ { sum += i } </pre> @@ -573,7 +573,7 @@ you should use parallel assignment. </p> <pre> // Reverse a -for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 { +for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 { a[i], a[j] = a[j], a[i] } </pre> @@ -708,10 +708,10 @@ and the next position. <pre> func nextInt(b []byte, i int) (int, int) { - for ; i < len(b) && !isDigit(b[i]); i++ { + for ; i < len(b) && !isDigit(b[i]); i++ { } x := 0 - for ; i < len(b) && isDigit(b[i]); i++ { + for ; i < len(b) && isDigit(b[i]); i++ { x = x*10 + int(b[i])-'0' } return x, i @@ -723,7 +723,7 @@ You could use it to scan the numbers in an input array <code>a</code> like this: </p> <pre> - for i := 0; i < len(a); { + for i := 0; i < len(a); { x, i = nextInt(a, i) fmt.Println(x) } @@ -760,7 +760,7 @@ of <code>io.ReadFull</code> that uses them well: <pre> func ReadFull(r Reader, buf []byte) (n int, err os.Error) { - for len(buf) > 0 && err == nil { + for len(buf) > 0 && err == nil { var nr int nr, err = r.Read(buf) n += nr @@ -1044,7 +1044,7 @@ the moment, this snippet would also read the first 32 bytes of the buffer. <pre> var n int var err os.Error - for i := 0; i < 32; i++ { + for i := 0; i < 32; i++ { nbytes, e := f.Read(buf[i:i+1]) // Read one byte. if nbytes == 0 || e != nil { err = e @@ -1067,7 +1067,7 @@ resulting slice is returned. The function uses the fact that <pre> func Append(slice, data[]byte) []byte { l := len(slice) - if l + len(data) > cap(slice) { // reallocate + if l + len(data) > cap(slice) { // reallocate // Allocate double what's needed, for future growth. newSlice := make([]byte, (l+len(data))*2) // Copy data (could use bytes.Copy()). @@ -1202,7 +1202,7 @@ do not take flags for signedness or size; instead, the printing routines use the type of the argument to decide these properties. </p> <pre> -var x uint64 = 1<<64 - 1 +var x uint64 = 1<<64 - 1 fmt.Printf("%d %x; %d %x\n", x, x, int64(x), int64(x)) </pre> <p> @@ -1355,7 +1355,7 @@ sets of values. type ByteSize float64 const ( _ = iota // ignore first value by assigning to blank identifier - KB ByteSize = 1<<(10*iota) + KB ByteSize = 1<<(10*iota) MB GB TB @@ -1371,17 +1371,17 @@ automatically for printing, even as part of a general type. <pre> func (b ByteSize) String() string { switch { - case b >= YB: + case b >= YB: return fmt.Sprintf("%.2fYB", b/YB) - case b >= PB: + case b >= PB: return fmt.Sprintf("%.2fPB", b/PB) - case b >= TB: + case b >= TB: return fmt.Sprintf("%.2fTB", b/TB) - case b >= GB: + case b >= GB: return fmt.Sprintf("%.2fGB", b/GB) - case b >= MB: + case b >= MB: return fmt.Sprintf("%.2fMB", b/MB) - case b >= KB: + case b >= KB: return fmt.Sprintf("%.2fKB", b/KB) } return fmt.Sprintf("%.2fB", b) @@ -1539,7 +1539,7 @@ func (s Sequence) Len() int { return len(s) } func (s Sequence) Less(i, j int) bool { - return s[i] < s[j] + return s[i] < s[j] } func (s Sequence) Swap(i, j int) { s[i], s[j] = s[j], s[i] @@ -1550,7 +1550,7 @@ func (s Sequence) String() string { sort.Sort(s) str := "[" for i, elem := range s { - if i > 0 { + if i > 0 { str += " " } str += fmt.Sprint(elem) @@ -1733,7 +1733,7 @@ has been visited? Tie a channel to the web page. type Chan chan *http.Request func (ch Chan) ServeHTTP(c *http.Conn, req *http.Request) { - ch <- req + ch <- req fmt.Fprint(c, "notification sent") } </pre> @@ -2110,14 +2110,14 @@ simultaneous calls to <code>process</code>. var sem = make(chan int, MaxOutstanding) func handle(r *Request) { - sem <- 1 // Wait for active queue to drain. + sem <- 1 // Wait for active queue to drain. process(r) // May take a long time. - <-sem // Done; enable next request to run. + <-sem // Done; enable next request to run. } func Serve(queue chan *Request) { for { - req := <-queue + req := <-queue go handle(req) // Don't wait for handle to finish. } } @@ -2141,10 +2141,10 @@ func handle(queue chan *Request) { func Serve(clientRequests chan *clientRequests, quit chan bool) { // Start handlers - for i := 0; i < MaxOutstanding; i++ { + for i := 0; i < MaxOutstanding; i++ { go handle(clientRequests) } - <-quit // Wait to be told to exit. + <-quit // Wait to be told to exit. } </pre> @@ -2182,9 +2182,9 @@ func sum(a []int) (s int) { request := &Request{[]int{3, 4, 5}, sum, make(chan int)} // Send request -clientRequests <- request +clientRequests <- request // Wait for response. -fmt.Printf("answer: %d\n", <-request.resultChan) +fmt.Printf("answer: %d\n", <-request.resultChan) </pre> <p> On the server side, the handler function is the only thing that changes. @@ -2192,7 +2192,7 @@ On the server side, the handler function is the only thing that changes. <pre> func handle(queue chan *Request) { for req := range queue { - req.resultChan <- req.f(req.args) + req.resultChan <- req.f(req.args) } } </pre> @@ -2219,10 +2219,10 @@ type Vector []float64 // Apply the operation to v[i], v[i+1] ... up to v[n-1]. func (v Vector) DoSome(i, n int, u Vector, c chan int) { - for ; i < n; i++ { + for ; i < n; i++ { v[i] += u.Op(v[i]) } - c <- 1 // signal that this piece is done + c <- 1 // signal that this piece is done } </pre> <p> @@ -2236,12 +2236,12 @@ const NCPU = 4 // number of CPU cores func (v Vector) DoAll(u Vector) { c := make(chan int, NCPU) // Buffering optional but sensible. - for i := 0; i < NCPU; i++ { + for i := 0; i < NCPU; i++ { go v.DoSome(i*len(v)/NCPU, (i+1)*len(v)/NCPU, u, c) } // Drain the channel. - for i := 0; i < NCPU; i++ { - <-c // wait for one task to complete + for i := 0; i < NCPU; i++ { + <-c // wait for one task to complete } // All done. } @@ -2282,12 +2282,12 @@ var serverChan = make(chan *Buffer) func client() { for { - b, ok := <-freeList // grab a buffer if available + b, ok := <-freeList // grab a buffer if available if !ok { // if not, allocate a new one b = new(Buffer) } load(b) // read next message from the net - serverChan <- b // send to server + serverChan <- b // send to server } } </pre> @@ -2298,9 +2298,9 @@ and returns the buffer to the free list. <pre> func server() { for { - b := <-serverChan // wait for work + b := <-serverChan // wait for work process(b) - _ = freeList <- b // reuse buffer if room + _ = freeList <- b // reuse buffer if room } } </pre> @@ -2377,7 +2377,7 @@ field for recoverable failures. </p> <pre> -for try := 0; try < 2; try++ { +for try := 0; try < 2; try++ { file, err = os.Open(filename, os.O_RDONLY, 0) if err == nil { return |