From: Robert Griesemer Date: Fri, 4 Feb 2011 16:43:21 +0000 (-0800) Subject: go spec, effective go: cleanups X-Git-Tag: weekly.2011-02-15~95 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=76f3228520cd862875d35b3f651be285b489b131;p=gostls13.git go spec, effective go: cleanups Removed most of the detailed examples about handing panics from the go spec since it's now covered by Effective Go. R=r, rsc, iant, ken2 CC=golang-dev https://golang.org/cl/4128058 --- diff --git a/doc/effective_go.html b/doc/effective_go.html index 9ca5e7eb3b..71d50c02b7 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -824,7 +824,7 @@ executions. Here's a silly example.

-for i := 0; i < 5; i++ {
+for i := 0; i < 5; i++ {
     defer fmt.Printf("%d ", i)
 }
 
@@ -1486,7 +1486,7 @@ for a min function that chooses the least of a list of integers: func Min(a ...int) int { min := int(^uint(0) >> 1) // largest int for _, i := range a { - if i < min { + if i < min { min = i } } @@ -2670,7 +2670,7 @@ suppresses the usual check for a return statement. // A toy implementation of cube root using Newton's method. func CubeRoot(x float64) float64 { z := x/3 // Arbitrary intitial value - for i := 0; i < 1e6; i++ { + for i := 0; i < 1e6; i++ { prevz := z z -= (z*z*z-x) / (3*z*z) if veryClose(z, prevz) { @@ -2727,7 +2727,7 @@ inside a server without killing the other executing goroutines.

-func server(workChan <-chan *Work) {
+func server(workChan <-chan *Work) {
     for work := range workChan {
         go safelyDo(work)
     }
@@ -2751,7 +2751,16 @@ calling recover handles the condition completely.
 

-Note that with this recovery pattern in place, the do +Because recover always returns nil unless called directly +from a deferred function, deferred code can call library routines that themselves +use panic and recover without failing. As an example, +the deferred function in safelyDo might call a logging function before +calling recover, and that logging code would run unaffected +by the panicking state. +

+ +

+With our recovery pattern in place, the do function (and anything it calls) can get out of any bad situation cleanly by calling panic. We can use that idea to simplify error handling in complex software. Let's look at an diff --git a/doc/go_spec.html b/doc/go_spec.html index 9784222195..2c6046a7c5 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ - +

Bootstrapping