Comment by barsonme

11 years ago

His Go is a little disingenuous. This (https://gist.github.com/EricLagerg/105431503d32f18d239b) is almost as short as his D code, and functions the same.

It's almost as if, like most people who write articles complaining about Go's lack of "expressiveness" and generics, he took a cursory look at the language, wrote some naive examples that supported his point, and squeezed out a blog post.

  • From the very first line of the article:

    >Over the course of the past few months I’ve been using Go to implement a proof of concept program in my spare time.

    It's almost as if, like most people who post on Hacker News, you took a cursory look at the title, wrote some inane comment that supported your point, and squeezed out a reply.

  • If the code was equivalent you might have a point. Unfortunately it is not (tokenizing/line scanning vs. copying). One has a shortcut in Go, the other does not.

    Would you say that Go is not excessively verbose in non-trivial use cases ? I recently had to sort a struct list in a program. Added lines of code for sorting a single list once : 30. What the ...

    • There's an equivalent method which can be called to read individual lines: ReadLine. There's also join and split methods to more naturally model what the D code is actually doing.

          fileBytes, _ := ioutil.ReadAll(<file>)
          text := string(bytes.Join(bytes.Split(fileBytes, '\n')))
          fmt.Println(text)
      

      > Added lines of code for sorting a single list once : 30. What the ...

      Sorting requires implementing three methods, at least one of which is usually given to you for free (Len). A simple case will usually cost about 9 lines of neatly formatted code, 3 if you're not so neat (which the Go sort library does itself).

          func (sl structSlice) Len() int { return len(sl) }
          func (sl structSlice) Less(i, j int) bool { return sl[i].MyKey < sl[j].MyKey }
          func (sl structSlice) Swap(i, j int) { return sl[i], sl[j] = sl[j], sl[i] }
      

      Ultimately, even this isn't a case of verbosity so much as it is not abstracting away the basic sorting functions.

      1 reply →

    • I'm curious about the specifics of your problem. I couldn't imagine sorting a list of structs (by one of the fields I presume) would be too terribly different in Go than in other langauges. Heres an example of insertion sort on a basic type: https://play.golang.org/p/SPoiNRVl2B

      You can use the standard library sort methods by making your type implement the sort interface. Heres an example taken from the example in the sort docs: https://play.golang.org/p/oeRIhHi1Ei

      2 replies →

    • For anything larger than a trivial program, go is no more verbose than python. For small programs, there's too much variance to really say what language is less verbose, because you can always hit cases where one language has something in the stdlib and one doesn't.

      The only place go is more verbose is sorting, and lack of map, filter, and list comprehension. Most of the latter just means you need a 3 line loop where you have one line in python. But that should not be a great effect on any reasonable size program.

      2 replies →