Skip to content

Conversation

@david-dorf
Copy link
Contributor

Description

"this->" seems to be unnecessary and examples work without it

Did you use Generative AI?

No

"this->" seems to be unnecessary and examples work without it

Signed-off-by: David Dorf <[email protected]>
Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

i am not really inclined to take this PR because of the following reasons.

Removing the explicit this-> qualifier inside class methods in C++ can make the code slightly shorter, but is there any other benefits from it?

on the other hand, with this->

  • it can be less obvious which variables and methods are members of the class and which are local variables or functions.
  • If a method or variable in the same scope has the same name as a class member, removing this-> can lead to unintended shadowing or bugs.
  • consistency with other examples in https://github.com/ros2/examples/tree/rolling/rclcpp/topics

if there is no downside to keep this->, i do not think it is worth to replace all of them?

@david-dorf
Copy link
Contributor Author

This PR would make things less verbose. It's only being removed from rclcpp functions in an intro node for beginners. It is highly unlikely a beginner would encounter a conflict with methods like get_logger()

@david-dorf
Copy link
Contributor Author

All good, if it's not worth it I'll close

@david-dorf david-dorf closed this Dec 21, 2025
@fujitatomoya
Copy link
Collaborator

@david-dorf thanks for sharing thoughts, feel free to reopen this. i think probably we would want to keep the consistency with other samples at least.

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