* 翻译建议
英文原著:
> the same operator <- is used for sending and receiving, but Go figures out depending on the operands what to do. Although not necessary, for readability the channel name usually starts with ch or contains ‘chan’. The channel send- and receive operations are atomic: they always complete without interruption.The use of the communication operator is illustrated in example
原译文:
>操作符 <- 也被用来发送和接收,Go 。尽管不必要,为了可读性,通道的命名通常以 ch 开头或者包含 chan。通道的发送和接收操作都是自动的:它们通常一气呵成。下面的示例展示了通信操作。
我的建议:
>同一个操作符 `<-` 既用于**发送**也用于**接收**,但Go会根据操作对象弄明白该干什么 。虽非强制要求,但为了可读性通道的命名通常以 `ch` 开头或者包含 `chan`。通道的发送和接收都是原子操作:它们总是互不干扰的完成的。下面的示例展示了通信操作的使用。
* 补个“符”字
* typical -> 典型
* 翻译建议
* Update 14.2.md
* Update 14.2.md
* Update 14.2.md
* 建议从翻译上调转了一下英文原著解释中的因果顺序
英文原著:
> 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!
我觉得这一句应该是因为编译器这种情况下不会报错才特地提醒的
虽然原文的这个句式有点让人费解...