-
Notifications
You must be signed in to change notification settings - Fork 111
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
suggestion: Use constant names rather than literals #59
Comments
How about a compile-time check in the form of a non-executable function like stringer? It has the benefit of causing an "invalid array index" error during compilation if An example with day names:
|
@dmarkham do you want to open a PR here? |
@andig unfortunately my fork is no longer compatible, mainly because I have pulled in some of the PRs and ideas from here and went a slightly different direction. My PR is referenced here mainly to let people know I liked and used the idea, as a thank you. |
@dmarkham @alvaroloes is there any overarching plan if both packages serve a different purpose in the future or should both continue to be maintained? |
Well in my mind these packages are just band-aids, waiting for real Enums in go. This package is widely used and stable. My package has more bells and whistles, that I wanted after researching what other forks, issues, and PRs that were getting submitted. They both are important. I just really wanted some of these features myself, and this package is just more conservative thus stable, and I think that's a good thing. I would rather move quickly, add the features, and I think that's a good thing also. |
When using enumer, it's possible to end up with something where the only places that a constant would be directly used would be in the conversion to/from string, but enumer doesn't use the constant, it uses a literal value.
See examples here:
dominikh/go-tools#660
So for instance
This could use
Monday
instead of the literal 0, and then it would be easier for analysis tools to detect that the constant value is in some way used. It might also be easier to read the resulting code, although I recognize that's not especially important with generated code.The text was updated successfully, but these errors were encountered: