Monday, March 30, 2015

Lessons learned from the First Go Challenge. The winning entries were Luke Champine and Jeremy Jay. Runner up was Doug Cichon.
  • Simplify by using methods, interfaces and composition.
    • Luke created a Decoder type (which sounds more like an interface) which was a wrapper around an io.Reader. That enabled him to create a composition such as err = NewDecoder(file).Decode(p). I find that to be very elegant.
    • Jeremy implemented a read method for both the Pattern type and the Track types. I like Jeremy's method better because it adds extenisbility if the read method had to be exported.
  • If I implemented this again, I would implement both read and decode methods on Pattern and Track types. Reader and Decoder are common interfaces in Go and it wouldn't take much to make Pattern and Track conform to those interfaces.
  • An os.File is an io.Reader. This should have been obvious.
  • binary.Read requires fields to be exported, but you can define structs with exportable fields within a function, in which the structs themselves are still essentially private to the package (see Luke's solution in the readHeader and readTrack methods).
See also this critique. I made a lot of these mistakes and it almost seems like several of the criticisms were pointed directly at my code!