Explain about feedback/result

Hi,
I see the code:
class ActionCustomMsg():
# create messages that are used to publish feedback/result
_feedback = CustomActionMsgFeedback()
_result = CustomActionMsgResult()

my question is: Why they do not code like:
def init(self,…):
self.feedback = CustomActionMsgFeedback()
self.result = CustomActionMsgResult()

Thanks

Hello @NguyenDuyDuc,

In Python programming the use of class variables (_variable) instead of instance variables (self.variable) are used to make sure that all instances of a class share a certain variable, instead of it depending on the instance of the class it belongs to.

In this case, the reason why class variables are used is that, according to the implementation, it would make sense for all instances of the class ActionCustomMsg to share the variables feedback and result, and therefore for them to be related to the class itself rather than the single instance.

This being said, it is mostly an implementation choice, the one you suggested would work as well.

I hope this helped, best regards,
Alessandro

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.