Monday, March 19, 2012

Some thoughts after using Go for a couple of days:
  • I like gofmt.
  • Having used Java for so long, I got tripped up by the passing by value of structs and had to change the parameters to pointers.
  • I also got tripped by the := declaration shadowing variables:

    func pop(n int, list []int) ([]int, error) {
    if n > len(list) {
    return list, errors.New("error")
    }
    return list[n:], nil
    }
    func multipop(counts []int, list []int) ([]int, error) {
    for _, n := range counts {
    list, err := pop(n, list) // Oops, a new variable named list
    if err != nil {
    return list, err
    }
    }
    return list, nil
    }
  • I like goroutines + a channel better than java.util.Iterator and Python gemerators, but not as much as lazy lists in Haskell for producer/consumer code.
  • containers/list looks very awkward compared to java.util.List, especially with Java generics. Generics are almost essential for useful containers, so Go inelegantly has the built-in function append and the built-in map data structure.

No comments:

Post a Comment