From cc6720aab7555190d0e19a04fd7b8e69caa17923 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 10 Nov 2009 00:09:53 -0800 Subject: [PATCH] Minor tweaks. The text changes are trivial and may be ignored, but there are two code corrections. R=r, rsc CC=go-dev http://go/go-review/1024045 --- doc/effective_go.html | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/effective_go.html b/doc/effective_go.html index 3c4ccecca2..5f1bf31bbf 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -286,7 +286,7 @@ The package name is only the default name for imports; it need not be unique across all source code, and in the rare case of a collision the importing package can choose a different name to use locally. In any case, confusion is rare because the file name in the import -defines which version is being used. +determines just which package is being used.

@@ -362,7 +362,7 @@ multiword names.

Go needs fewer semicolons between statements than do other C variants. Semicolons are never required at the top level. -Also they are separators, not terminators, so they +And they are separators, not terminators, so they can be left off the last element of a statement or declaration list, a convenience for one-line funcs and the like. @@ -656,8 +656,8 @@ case *int:

Multiple return values

-One of Go's unusual properties is that functions and methods -can return multiple values. This feature can be used to +One of Go's unusual features is that functions and methods +can return multiple values. This can be used to improve on a couple of clumsy idioms in C programs: in-band error returns (such as -1 for EOF) and modifying an argument. @@ -745,7 +745,7 @@ of io.ReadFull that uses them well:

 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;
@@ -1162,7 +1162,7 @@ return a string rather than filling in a provided buffer.
 

You don't need to provide a format string. For each of Printf, -fmt.Fprintf and fmt.Sprintf there is another pair +Fprintf and Sprintf there is another pair of functions, for instance Print and Println. These functions do not take a format string but instead generate a default format for each argument. The ln version also inserts a blank @@ -1175,7 +1175,9 @@ fmt.Fprint(os.Stdout, "Hello ", 23, "\n"); fmt.Println(fmt.Sprint("Hello ", 23));

-Recall that fmt.Fprint and friends take as a first argument any object +As mentioned in +the tutorial, fmt.Fprint +and friends take as a first argument any object that implements the io.Writer interface; the variables os.Stdout and os.Stderr are familiar instances.

@@ -1428,7 +1430,7 @@ func init() {

Pointers vs. Values

-Methods can be defined for any named type except pointers and interfaces; +Methods can be defined for any named type that is not a pointer or an interface; the receiver does not have to be a struct.

In the discussion of slices above, we wrote an Append @@ -2078,7 +2080,8 @@ Receivers always block until there is data to receive. If the channel is unbuffered, the sender blocks until the receiver has received the value. If the channel has a buffer, the sender blocks only until the -value has been copied to the buffer. +value has been copied to the buffer; if the buffer is full, this +means waiting until some receiver has retrieved a value.

A buffered channel can be used like a semaphore, for instance to @@ -2147,7 +2150,7 @@ Here's a schematic definition of type Request. type Request struct { args []int; f func([]int) int; - resultChan <-chan int; + resultChan chan int; }