-
Notifications
You must be signed in to change notification settings - Fork 560
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
Do not pass and return simple types by const ref #859 #2119
Conversation
re.compile(r"\b(const\s(bool|char|short|int|long|float|double|void))\s*&\s*")
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2119 +/- ##
==========================================
+ Coverage 50.73% 50.74% +0.01%
==========================================
Files 386 386
Lines 31970 31970
==========================================
+ Hits 16216 16219 +3
+ Misses 15754 15751 -3
☔ View full report in Codecov by Sentry. |
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.
CI fails for unrelated formatting reasons /~https://github.com/ros-planning/moveit2/actions/runs/4862228141/jobs/8670864807?pr=2119#step:12:9677. I'm fine with these changes in general. @tylerjw what do you think?
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'm also fine with these changes. I do think having const
in parameters where it is meaningless should also be removed.
Here is what I mean. Take this function you want to improve:
void do_magic(const int& input_number);
If you change it to this (just remove the &) you leave const
which is meaningless in modifying the int
. Previously it modified the way the &
worked but that is no longer there:
void do_magic(const int input_number);
A much better change in my opinion is to also remove the const keyword in cases where we took a const&
and made it a value parameter like this:
void do_magic(int input_number);
Thanks for the suggestions @tylerjw. What are the advantages of not using const? Is it really bad to use a const, if it is not necessary? |
Without the reference, the function is getting a copy. The rationale is that if you're passing a copy already, The function/method could still change its argument, but that would not affect the variable/value that was passed to it. Hence no need for (this is not the only opinion about this btw. Some developers consider the |
More details than you probably asked for: Because of the C model of separating declaration (the type found in headers) and definition (the details found in the source file) the keyword There is nothing in the way C or C++ encodes At the same time you can put I am a fan of local const variables but 🤷. I think C++ is already a language full of noise so we should avoid adding keywords that have no symantic meaning and are ignored by the compiler. |
Thanks @gavanderhoorn and @tylerjw for the detailled explanation, that was exactly what i was looking for. If it is consensus to remove the const keyword, i can make the change as soon as i find the time (hopefully within 1 week). |
This PR is stale because it has been open for 45 days with no activity. Please tag a maintainer for help on completing this PR, or close it if you think it has become obsolete. |
Yes, please remove const where it is meaningless (value parameters). |
The clang-tidy warnings in CI will be fixed by #2343 |
This pull request is in conflict. Could you fix it @Nils-ChristianIseke? |
@Shobuj-Paul you are welcome to take over this work and finish it. Ping me for reviews. |
This pull request is in conflict. Could you fix it @Nils-ChristianIseke? |
Merged with #2453 |
Thanks for catching up on this issue @Shobuj-Paul. |
Description
Removed const references of simple types with regex.
Checklist