3 ms·
1. Go encourages short variable names. I personally think that the names used in the example you pulled are a touch shorter than I myself would use, and "prevRu
by dradtke 12y ago
1. Go encourages short variable names. I personally think that the names used in the example you pulled are a touch shorter than I myself would use, and "prevRune" is a little bit ambiguous, but I don't really mind it since the context makes it more clear.
2. Yes, int64() is a cast to an int64 type. The bare "int" type in Go is architecture-dependent, so the compiler will complain if you try to assign an int to an int64 without the cast.
3. Rune is a number representing a UTF-8 codepoint. It's an alias for int32 the way "byte" would be an alias for in8. (http://golang.org/doc/go1#rune http://golang.org/doc/go1#rune)
4. copy() is a built-in function. There's only a small handful of built-in functions defined, and they're all documented here: http://golang.org/pkg/builtin/ http://golang.org/pkg/builtin/
5. The last return statement doesn't specify any values because the method signature has already assigned names to those: n for the int, and err for the error, so an empty return means "return the values of the variables n and err", which default to their respective type's 0 values (0 and nil for int and error). Returning the values explicitly still works as seen in that example, and is slightly shorter than "n = 0; err = io.EOF; return".
Go can be tricky to read if you're not familiar with some of the semantics, but once you've ramped up a little bit, then things just start falling into place.