litter
litter copied to clipboard
Options is not forwards-compatible
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.
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
We're at 1.1. 😉