sanity-io / litter

Litter is a pretty printer library for Go data structures to aid in debugging and testing.
MIT License
1.53k stars 54 forks source link

Options is not forwards-compatible #14

Open erikgrinaker opened 6 years ago

erikgrinaker commented 6 years ago

The recommended way to configure an individual Litter instance is via an Options struct literal, e.g:

  sq := litter.Options {
    HidePrivateFields: true,
    HomePackage: "thispack",
    Separator: " ",
  }

  sq.Dump("dumped", "with", "local", "settings")

This is not forwards-compatible, since any missing fields will be initialized to their zero-values. If a future field with a non-zero default is introduced, e.g. DontCrash: true, then all old code that uses custom options will break.

I believe the best practice in the Go community is to either have structs that default to their zero values, or use a constructor. Litter currently does neither, as the default config is:

var Config = Options{
    StripPackageNames: false,
    HidePrivateFields: true,
    Separator:         " ",
}

Not sure what the best approach would be, this is just an observation.

simen commented 6 years ago

Good point. I just nicked that pattern from Spew, but I agree it is not particularly awesome. We'll have to come up with something better for 1.0

atombender commented 6 years ago

We're at 1.1. 😉