In the following code, I'm trying to write a Txt() function to pretty print out my structure. It contains following minor questions in the full code:
full code at: http://play.golang.org/p/nUsg_qbufP
Some questions:Why do you need to re-type byte as Char? By doing so, you're making []byte (which is a "slice", not an "array") conversion-incompatible with []Char. I don't see any methods on Char, for example, or any other reason why you'd really need to avoid using byte directly. Also, in Go, it's much more common to type a container, such as `type Chars []byte` rather than an element, as you do with `type byte Char`, and even that isn't often done unless methods are defined on the named type. Nonetheless, you can initialize []Char from a string by doing: []Char("the string")
You cannot initialize a byte-array (or Char-array) with a fixed length from a string. Usually that does not come up as an issue, since for constant immutable data, strings are preferably used. When you really need to initialize an array, either the way you're doing it, element by element in an array literal, or slicing it and using copy (or doing something in a loop) are the only real means of initialization.
reflect, while not necessarily slower than in other reflective languages, is much slower than not using reflection. That said, fmt uses reflection in all but the easy cases, and for output, it's reasonably fast enough.See reflect.Kind, and the reflect.Type and reflect.Value Kind method. You can check that against the constant reflect.Array to see if something is an array, and use reflect.Type's Elem method to get the element type for an array, slice, chan, etc. You can compare the returned element type for equality with reflect.TypeOf(Char(0)) to see if the element type is a Char, without needing to do any string manipulation.
On Apr 8, 2013 5:46 AM, "dlin" <dli...@gmail.com> wrote:
>
> As I know google plans to close google reader. So, I post the question to stackoverflow too.
>
Just note that Google Reader != Google Groups.