Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thought about adding a small remark something like this (but I am not sure if it is the best place here):
Using a runtime/dynamic string in this
printf
style context is almost always a bad idea and the_STREAM
variant would be perfectly fine for this task.I think this also completely resolves the problem from the above mentioned PR, as using the
_STREAM
variant should have no downsides and has the benefit of being safe.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 disagree with this assessment (so I'm glad it is not in this PR :). In particular, there are situations where it is helpful to build up a string at runtime that you then both want to output to the log (via
RCLCPP_WARN
or whatever), and then also use for another purpose (like as a return value). While I guess you can use STREAM for that, I also don't see much of a problem with: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.
Sorry my messaging was probably not so clear. What you have in your example is perfectly fine.
What I am afraid of is people doing is this:
(this example is from #570)
In the companies I worked at the unqualified macros where only used if there is no interpolation at all and otherwise my colleagues always used the
_STREAM
variant, which gave me the impression that this is the "typical" behavior.In this case I thought using the
_STREAM
macro would be much more intuitive and especially steer away from the example above (which I know unfortunately have already seen in our codebase).Your example would also work with the
_STREAM
:I am also perfectly fine with just removing the line, so that we can close this PR.