Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options is not forwards-compatible #14

Open
erikgrinaker opened this issue Nov 23, 2017 · 2 comments
Open

Options is not forwards-compatible #14

erikgrinaker opened this issue Nov 23, 2017 · 2 comments

Comments

@erikgrinaker
Copy link
Contributor

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
Copy link
Member

simen commented Dec 5, 2017

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
Copy link
Member

We're at 1.1. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants