-
Notifications
You must be signed in to change notification settings - Fork 15
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
Use constructors for static tokens #29
base: master
Are you sure you want to change the base?
Conversation
WARNING: This commit includes breaking changes. Instead of global variables, use function constructors for static tokens such as Null, ObjectStart, ObjectEnd, ArrayStart, and ArrayEnd. This provides a greater degree of immutability for the API. Note that static tokens for True and False are dropped in favor of the pre-existing Bool constructor. If necessary, we can already re-introduce True and False.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I might have left it as it was before - lots of std packages have the immuntability issue with e.g. var ErrFoo = ...
, and in practice it's not an issue. But SGTM either way.
One advantage of this is that it makes In godoc, variables are given less prominence than functions (e.g., variables never show up in the table of contents, while functions do). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like this better even if historically I take the point Dan makes
I think it is fine. We did the same thing for "constant" values in go-kit/log/level. https://github.com/go-kit/log/blob/0b69c7049332e99c25d5fd0f4d08317cfe45e7d8/level/level.go#L204-L239 |
SGTM with the assumption the compiler is/will be clever enough to handle this efficiently |
I prefer the old scheme. If it's for immutability, can we set these enums to const string and expose the rawToken helper function? |
WARNING: This commit includes breaking changes.
Instead of global variables, use function constructors for static tokens such as Null, ObjectStart, ObjectEnd, ArrayStart, and ArrayEnd. This provides a greater degree of immutability for the API.
Note that static tokens for True and False are dropped in favor of the pre-existing Bool constructor.
If necessary, we can always re-introduce True and False.