litter icon indicating copy to clipboard operation
litter copied to clipboard

Options is not forwards-compatible

Open erikgrinaker opened this issue 7 years ago • 2 comments
trafficstars

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.

erikgrinaker avatar Nov 23 '17 09:11 erikgrinaker

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

simen avatar Dec 05 '17 07:12 simen

We're at 1.1. 😉

atombender avatar Dec 05 '17 16:12 atombender