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

Nudge people to use custom comparers #115

Merged
merged 1 commit into from
Feb 28, 2019
Merged

Conversation

LMMilewski
Copy link
Contributor

Currently we put push users towards options that handle unexported fields. A common scenario is:

  1. someone uses cmp.Diff on big.Int (transitively)
  2. they get a message that advertises Ignore/Allow Unexported options
  3. they see that AllowUnexported is hard to use correctly
  4. they use IgnoreUnexported
    They end up with:
    cmp.IgnoreUnexported(big.Int{})
    Which definitely doesn't do what's intended.

If we point out that a custom comparer is what they most likely need, then they are more likely to use cmp correctly.

Copy link
Collaborator

@dsnet dsnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Philosophically, I think this is in the right direction.

go.mod Outdated Show resolved Hide resolved
cmp/options.go Outdated Show resolved Hide resolved
cmp/cmpopts/ignore.go Outdated Show resolved Hide resolved
…ted options.

A common scenario is:
  1. someone uses cmp.Diff on big.Int (transitively)
  2. they get a message that says uses Ignore/Allow Unexported options
  3. they see that AllowUnexported is hard to use correctly
  4. they use IgnoreUnexported
They end up with:
  cmp.IgnoreUnexported(big.Int{})
Which definitely doesn't do what's intended.

If we point out that a custom comparer is what they most likely need, then they are more likely to use cmp correctly
@LMMilewski
Copy link
Contributor Author

done, PTAL

@dsnet dsnet merged commit c812816 into google:master Feb 28, 2019
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

Successfully merging this pull request may close these issues.

2 participants