* 建议从翻译上调转了一下英文原著解释中的因果顺序
英文原著:
> Notice the use of the closure: the current i, xi are passed to the closure as parameters, masking the i, xi variables from the outer for-loop. This allows each goroutine to have its own copy of i, xi; otherwise, the next iteration of the for-loop would update i, xi in all goroutines. On the other hand, the res slice is not passed to the closure, since each goroutine does not need a separate copy of it. The res slice is part of the closure’s environment but is not a parameter
原译文:
>注意闭合:i、xi 都是作为参数传入闭合函数的,从外层循环中隐藏了变量 i 和 xi。让每个协程有一份 i 和 xi 的拷贝;另外,for 循环的下一次迭代会更新所有协程中 i 和 xi 的值。切片 res 没有传入闭合函数,因为协程不需要单独拷贝一份。切片 res 也在闭合函数中但并不是参数。
我的建议:
>注意上述代码中闭合函数的用法:`i`、`xi` 都是作为参数传入闭合函数的,这一做法使得每个协程有一份 `i` 和 `xi` 的拷贝,从而向闭合函数内部隐藏了外层循环中的变量 `i` 和 `xi`;否则,for 循环的下一次迭代会更新所有协程中 `i` 和 `xi` 的值。另一方面,切片 `res` 没有传入闭合函数,因为协程不需要`res`的单独拷贝。切片 `res` 也在闭合函数中但并不是参数。
* 增加了译者注和一些用词调整
page:183
Exercise 7.14: string_reverse.go:Write a program that reverses a string, so “Google” is printed as ” elgooG”. (Hint: use a slice of bytes and conversions.)If you coded a solution with two slices, try a variant which uses only one (Hint: use swapping) If you want to be able to reverse Unicode-strings: use [ ]int !
Within a package, however, especially if there are deeply nested calls to non-exported functions, it can be useful (and improve readability) to use panic to indicate error conditions which should be translated into an error for the calling function.
原译文有机翻的感觉。鉴于英文原文这一段的句式,我觉得意思表达到了就行。
Exercise 12. 6:cat_numbered.go
Extend the example from listing 12.8 to process a flag which indicates that every line read should be preceded by a line number in the output. Test it out with: cat –n test
原文:
A Go string is thus a sequence of variable-width characters (each 1 to 4 bytes, see Ex. 4.6), contrary to strings in other languages as C++, Java or Python that are fixed-width (Java uses always 2 bytes).
因此改为 “Go 中的字符串里面的字符” 更合适。
* 翻译更正+译者注
原文:concatenates the string with itself.
为了便于理解增加了译者注
* 原书此处也是11.9,但实际上指的是练习11.11
原书此处也是11.9,但实际上指的是练习11.11
* 此处英文版原书有误,应该是练习10.16和10.17
* 原书此处有误,因为方法无法同时使用命名过的返回值和未命名的返回值
会报错:Method specification has both named and unnamed return parameters '(x interface{}, error)'
* 补漏+易读性提升
A function which has a (one or more) parameter of an interface type can be called with a variable(此处译文中漏掉) whose type implements that interface.
其**实参**可以是任何实现了该接口的类型的变量
原文:This goes wrong of course when the original value items are not unique; in that case no error occurs, but the processing of the inverted map is simply stopped when a nonunique key is encountered, and it will most probably not contain all pairs from the original map!
我觉得这一句应该是因为编译器这种情况下不会报错才特地提醒的
虽然原文的这个句式有点让人费解...
the first element of `argv` should be the command self which is 'ps' in this case, as the official doc says: "The argv slice will become os.Args in the new process, so it normally starts with the program name."