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

WIP: (Low priority) Use enum struct and drop enum variant prefixes #3453

Closed
wants to merge 5 commits into from

Conversation

Ericson2314
Copy link
Member

This does a few enums; the rest will be gotten in subsequent commits.

Thanks @jhartzell42 for teaching me about this. It's better practice in C++, and, as a bonus, it's closer to Rust shold we wish to rewrite more :O.

@edolstra I know this is a lot of churn. I'll be happy to take care of the merge into the flakes branch (or other branches you deem important) if you like, to lessen the cost of this on other devs.

@Ericson2314 Ericson2314 changed the title Use enum strut and drop prefixes Use enum struct and drop prefixes Mar 29, 2020
@Ericson2314
Copy link
Member Author

Hmm. CI timed out.

@andir
Copy link
Member

andir commented Mar 29, 2020

It did not really time out. You are running in a bunch of these errors on Darwin:

2020-03-29T03:50:22.9693600Z lib/Nix/Store.xs:109:55: error: use of undeclared identifier 'Base32'
2020-03-29T03:50:22.9694240Z             auto s = info->narHash.to_string(base32 ? Base32 : Base16);
2020-03-29T03:50:22.9694380Z                                                       ^
2020-03-29T03:50:22.9694870Z lib/Nix/Store.xs:109:64: error: use of undeclared identifier 'Base16'
2020-03-29T03:50:22.9695340Z             auto s = info->narHash.to_string(base32 ? Base32 : Base16);

@Ericson2314
Copy link
Member Author

Oh oops I read the wrong one. Thanks!

This does a few enums; the rest will be gotten in subsequent commits.
@Ericson2314
Copy link
Member Author

OK! this all up date and ready to go.

@Ericson2314 Ericson2314 changed the title Use enum struct and drop prefixes Use enum struct and drop enum variant prefixes May 29, 2020
@Ericson2314
Copy link
Member Author

@edolstra This PR in particular especially clutters up the other more interesting PRs that contain it. It would be great if we could merge it soon. My offer still stands to get rid of any conflicts in the flakes after merging :).

@edolstra
Copy link
Member

edolstra commented Jun 3, 2020

I'm not really in favor of this. It's a huge amount of code churn for no real advantage (as far as I can see). I mean, what's the benefit to writing Verbosity::Info instead of lvlInfo?

@Ericson2314
Copy link
Member Author

Ericson2314 commented Jun 3, 2020

My apologies for not expounding "better practice in C++", but it appears according to https://en.cppreference.com/w/cpp/language/enum that these "scoped enumerations" have fewer implicit conversions than their unscoped equivalents. I would think that's some real value as we don't want numbers sneaking through.

In addition, I still find the code with change easier to read:

  1. Identifiers beginning with a lower case character usually have much smaller scopes.

  2. The common prefix does indicate the variants are for the same enum, but doesn't indicate what which enum that is.

I'd hope one of the main benefits of not keeping a stable API in Nix anyways is that there is little-to-no marginal cost in doing slight cleanups like there. Each one is small, but they'll compound over time. And with my promise to go through any unmerged branch you like to resolve the conflicts, I hope the churn wouldn't impact you at all.

But if you still don't like this, we can close it and I'll go remove it from the other PRs it's included in. That will be tedious, but is self-inflicted on my part, so I'm not asking that it affect your decision.

@Ericson2314 Ericson2314 changed the title Use enum struct and drop enum variant prefixes (Low priority) Use enum struct and drop enum variant prefixes Jun 19, 2020
@Ericson2314 Ericson2314 changed the title (Low priority) Use enum struct and drop enum variant prefixes WIP: (Low priority) Use enum struct and drop enum variant prefixes Jul 17, 2020
@Ericson2314
Copy link
Member Author

If we have fix all the lower hanging fruit such that churn like this is deemed with it, I assume it will be easier to just sed afresh from scratch.

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.

None yet

4 participants