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

Remove unneeded optional from ParserResult #2042

Open
wants to merge 15 commits into
base: mauro/runtime-config-reflection
Choose a base branch
from

Conversation

JoukoVirtanen
Copy link
Contributor

Description

Removes optional from using ParserResult = std::optional<std::vector<ParserError>>; and makes other changes so that things are consistent.

Checklist

  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

Unit tests should be sufficient.

Copy link
Collaborator

@Molter73 Molter73 left a comment

Choose a reason for hiding this comment

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

Hey @JoukoVirtanen! Thanks for putting this PR together.

I appreciate that removing the std::optional from ParserResult simplifies access to it very slightly, but as I mentioned in my other comment, it does so by being less idiomatic C++17 and making it harder to convey its intention, checking if there are errors is a lot easier to read with if (errors) than if (!errors.empty()), which is a C++11 idiom that was used because there was no better alternative.

With that said, if it's up to me, I wouldn't move forward with this change.

@@ -488,9 +480,9 @@ ConfigLoader::Result ConfigLoader::LoadConfiguration(const std::optional<const Y
errors = parser_.Parse(&runtime_config, *node);
}

if (errors) {
if (!errors.empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really like this, if (errors) { is a much more idiomatic way to express that you will execute something if errors happened when compared to if (!errors.empty()) {. Performance wise, both options should be the same, because we create vectors in the inner methods, so not much difference there and this code is not in any hot path, so I wouldn't worry about it.

@Molter73 Molter73 force-pushed the mauro/runtime-config-reflection branch from 62700c0 to 8e71a90 Compare February 14, 2025 11:15
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