-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Access ConfigObjects by predefined constants instead of plain strings #4223
Conversation
Pull Request Test Coverage Report for Build 1152289915
💛 - Coveralls |
What is the advantage of using namespaces and the extern keyword from ANSI-C legacy. For my understanding it is a big benefit to use classes, that the the compiler is able to do some sanity checks. |
Why should we enclose constants in classes instead of namespaces?? The heavy-weight |
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.
The issue with "extern" comes up when you have typos in the cpp file:
In this case you get the linker error like that, without a hint where the typo is:
undefined reference to `mixxx::library::prefs::kLegacyDirectoryConfigKey'
Including the library_prefs.h in the library_prefs.cpp is redundant in you current implementation.
If you do the same with a class, you get a compiler way earlier error with a detailed location:
library_prefs.cpp:27:5: error: ‘const ConfigKey mixxx::library::prefs::kLegacyDirectoryConfigKey1’ is not a static data member of ‘class mixxx::library::prefs’
I have just noticed that you can achieve an early compiler error as well, if you remove the inner namespace and use it as prefix
library_prefs.cpp:8:24: error: ‘mixxx::library::prefs::kLegacyDirectoryConfigKey1’ should have been declared inside ‘mixxx::library::prefs’
That solves the issue for me.
I have removed the nested namespaces in the .cpp file. But this requires a comment that explains the reason why this is needed. We should strive to find a fool-proof solution that could be applied to all use cases in a straight-forward manner. |
The current solution with the extra comment is already good IMHO. |
I wonder why only the Windows build failed? https://github.com/mixxxdj/mixxx/pull/4223/checks?check_run_id=3386161822 Should work now, let's see. We could use this as the starting point and keep an eye on usability issues that might occur while migrating more |
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.
OK, LGTM. Thank you.
...just migrated some config keys as a starting point and prerequisite for #4218.
An attempt to tame the chaotic string-based access to configuration settings. Please give feed back what you think about it. The
_prefs.h
file serves a similar purpose as the_decl.h
file. Instead of static class members namespaces are used. You don't need the whole class definition for this purpose, only some shared constants.