-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use of std::bind in C++ code examples #3618
Comments
While I know that Whether we should change the default beginner example to use lambdas I'm more ambivalent about. I don't feel like lambdas are substantially easier to explain than |
It's also a very common pattern in ROS 1 code, as |
This is tricky. C++ is just a difficult language since there are 99 ways of doing everything, most of which will happily compile and then sometimes result in undefined behavior 💥 🤦 That being said, I agree it's most programmer-friendly to use mainstream practices wherever we can. I'm in favor of having the default entry docs use lambdas since these days it's the most common practice. A lot has changed in the C++ world since these examples were first written. I do think it's tough to learn lambdas at first, because the syntax is all just punctuation without any tokens that you can type into a search engine to find help. But, hopefully many/most people using the API will already be familiar with lambdas from other contexts in modern C++ since they are now so common. I'd be in favor of keeping the Thank you for looking into this and improving the documentation! 🤩 |
We discussed this more, and the general feeling is that we should move more of our examples, particularly the default examples, to use lambdas. That said, we should still keep around examples (and some documentation) that uses So with that said, @FelipeGdM we'd welcome changes to the documentation that made this update. Thanks! |
Hi everyone!
In the tutorial page Writing a simple publisher and subscriber (C++), the code example provided for the MinimalPublisher uses the C++11 function
std::bind
at the wall timer creationIn C++14 and later, lambda expressions are found to be preferred as they are easier to write and understand than
std::bind
. Static analyzers such as clang-tidy and SonarSource consider the use ofstd::bind
as a code smell in C++14 and newer versionsAs a personal comment, I found this line of code to be the most difficult to explain to ROS 2 newcomers, as usually students tend to learn ROS 2 at the same time they are learning modern C++. Any improvement of the readability of the Beginner Tutorials may be a huge benefit when teaching ROS 2 to newbies
The ROS 2 cpp examples folder already have a publisher example using lambda expressions, so my question is, is there any reason to keep the
std::bind
version in the docs page?If the answer is no, I would gladly update it to use a more readable and modern idiom of C++
Kind regards,
Felipe Gomes de Melo
The text was updated successfully, but these errors were encountered: