Jump to content
drjdpowell

[LVTN] Messenger Library

Recommended Posts

Hello, I have a little question about programming style.

What do you think of using typedefs for message data?

On the one hand when type changes in once place, all actors will get an update.
On the other hand it creates additional coupling between actors. I am not sure
what approach is better and why.

Thank you!

Share this post


Link to post
Share on other sites
On 1/30/2020 at 10:00 AM, Maksim Kuznetsov said:

What do you think of using typedefs for message data?

I don't tend to use them unless they have meaning beyond the message itself (ie. they are a natural grouping of data, rather than something that just exists for the message).  Most of my messages contain only one piece of data, so no typedef needed (unless that data is naturally a typedef).  Also, it is possible to go more than just a typedef: have an API of subVIs to send and receive the messages in a common library.  This can be a lot more powerful than just a typedef.  An example would be having any message starting with "Config:..." being passed to a Config subVI, with multiple possible messages being handled by that subVI ("Config: Get as JSON","Config: Set from JSON", etc.).  Another option is to send an Object that has multiple methods that the receiving actor can use.  I view a typedef as a poor cost-benefit trade-off, since you have the coupling issue without the maximum possible benefits.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you once again Dr. Powell for sharing this powerful approach. I can see it being used in "Metronome" actor (e.g. Set Period).
And I already started to use it in my projects.

If you don't mind I would like to ask you another question: I have an actor (A) that launches a sub-actor (B) to delegate some tasks to it.
When sub-actor (B) publishes an event, actor (A) gets a message. However I would like to publish that message beyond actor (A). So that actors subscribed
to actor (A) would also receive events from sub-actor (B).

Currently my approach is to send Observer Registry of actor (A) to sub-actor (B) during initialisation. Then sub-actor (B) publishes its events into Observer Registry of actor (A) directly.
Another idea was to republish the event from actor (A) when it gets the message from sub-actor (B). Neither of these methods feel right to me. The first one shares internal reference
of the actor (A). The second method is not as efficient (receives, then sends again).

How would you approach this?

  • Like 1

Share this post


Link to post
Share on other sites

I have always done the second method, and just accepted the extra overhead of one extra message pass. Beware of premature optimization.  It is generally rare for me to want to just forward a message like this without the forwarding actor needing to change or react to the message in some way.

An alternate design is to accept that you don't have an actor-subactor relationship, but that your subactor should really be a helper loop of the actor.  A dedicated helper loop can share references no problem.  Your "actors sharing references" is a potentially suboptimal mix of "actors are highly independent but follow restrictive rules" and "helper loops have no restrictions but are completely coupled to their owner"

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.