News for hackers. Stuff that matters.
Re:Impressions of Go by mratzloff on Tuesday July 23, 2013 @12:38PM (#6091125)
About the "no generic / you have to cast ,recast / the make issue" , could anyone here with a bit of experience gives an example of what that would look like in real code ?

Sure. Say you have a Set type (which is custom, since Go doesn't provide a `container/set` type.

    type Set struct {
        set map[interface{}]bool
    }
All of the methods (`Add()`, `Contains()`, etc.) are going to be declared with `interface{}` parameters, e.g.,

    func (set *Set) Add(x interface{}) bool
You would also want a method to get a slice of all members, e.g.,

    func (set *Set) Members() []interface{}
If you want to use this as a set of strings, you would add without a cast:

    mySet.Add("foo")
However, when pulling it out you would need to cast it to a string. So if you were converting `[]interface{}` to `[]string`, it would look like this:

    values := make([]string, mySet.Len())
    for i, member := range mySet.Members() {
        values[i] = member.(string)
    }
Re:Impressions of Go by axelf on Tuesday July 23, 2013 @01:16PM (#6091419)
But since you have to use casts you are giving up some advantages of static typing, right?
Re:Impressions of Go by mratzloff on Tuesday July 23, 2013 @01:25PM (#6091488)
Yes, but the `container/list` standard library uses the same approach.

I wrote a Cartesian product library that took a different tack--it splits the index and iterator cursor logic (integer fiddling) into one struct and the actual type into another, so it's easy to build type-checked objects.

In full disclosure, though, that was mainly because the alternative (using `interface{}`) was so utterly painful.

Re:Impressions of Go by Jayschwa on Tuesday July 23, 2013 @03:04PM (#6092208)
That sounds interesting and useful. Is that code publically available anywhere?
Re:Impressions of Go by mratzloff on Tuesday July 23, 2013 @07:44PM (#6093637)
No, unfortunately. It is proprietary.