From c072558b90f1bbedc2022b0f30c8b1ac4712538e Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Fri, 18 Feb 2011 09:50:58 +0100 Subject: Imported Upstream version 2011.02.15 --- doc/effective_go.html | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'doc/effective_go.html') diff --git a/doc/effective_go.html b/doc/effective_go.html index 3f6f89b8b..8f94f467b 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) { @@ -2705,7 +2705,7 @@ func init() {

When panic is called, including implicitly for run-time -errors such indexing an array out of bounds or failing a type +errors such as indexing an array out of bounds or failing a type assertion, it immediately stops execution of the current function and begins unwinding the stack of the goroutine, running any deferred functions along the way. If that unwinding reaches the top of the @@ -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 @@ -2876,7 +2885,7 @@ func main() { } func QR(w http.ResponseWriter, req *http.Request) { - templ.Execute(req.FormValue("s"), w) + templ.Execute(w, req.FormValue("s")) } func UrlHtmlFormatter(w io.Writer, fmt string, v ...interface{}) { -- cgit v1.2.3