LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Objects Containing References - Discussion

During Q&A in one of his "An End to Brainless Programming" presentations, Darren mentioned that classes wrapping any references should only contain references (From the 2020 GLA Summit - see https://youtu.be/pS1UBZzKl9k?t=1741). This makes sense to me to some degree, as usually you don't want any associated data to be no longer synchronized with an internal reference after branching a wire.


It is still a new concept to me, though - if people are willing, I would like to hear more discussion/reasoning on the topic before I wholeheartedly adopt it as a personal rule.

Do you know of any other forum posts/whitepapers/recorded presentations on the topic - Darren mentioned Aristos Queue having talked about this before? Do you agree with this as a general rule? I assume that any classes containing an object that wraps references also should only contain references - is this correct? Should this rule also apply to normal clusters containing references? Can you think of any exceptions that might make a class with both value and reference data appropriate?

I did look through some NI APIs for exceptions, and found a couple in the Actor Framework's message classes: Actor Framework.lvlib:LastAck.lvclass wraps a by-val error cluster along with some objects containing only references (Actor.lvclass and Message Enqueuer.lvclass); Actor Framework.lvlib:Launch Nested Actor Msg.lvclass wraps a by-ref actor.lvclass with some by-val data.

Crossposted to LAVA here: Objects Containing References - Discussion - Object-Oriented Programming - LAVA (lavag.org)

0 Kudos
Message 1 of 5
(1,432 Views)

I would agree in principle that an object should either be by-value or by-reference. However, I can see where some items can be by-value in a by-reference class. These items would be static data that is only ever initialized once at the creation of the class. Essentially WORM (Write Once, Read Many) data elements. Any data that could ever be modified in a by-refernce class should be accessed via a reference so all branchs are kept in synch.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 5
(1,340 Views)

I don't think it's wrong to mix them, exactly, but once you add by-value data then the whole class becomes effectively by-value and you can't split the wire anymore (outside of the WORM data Mark mentioned) without duplicating your by-value parts of the object.

 

That said, I can't really think of a good non-singleton class that would benefit from a mixture of by-val's and by-ref objects. The two AF examples you gave are WORM data. The values don't get updated after they're originally created.

Message 3 of 5
(1,324 Views)

You should definitely be careful with mixing.

 

There are cases where I think it's beneficial, maybe even unavoidable.

 

If you'd have, for example, a by reference data bus class (store data here, read it there), you might have methods to 'query' the data. There might be tons of query options, too many for a connector pane. You'd have a few option: make an option class, or but the options in the private data. Those options would not make any sense as by reference data. That would mean that setting options in one place would alter the results in another place.

 

Private data can take all forms and shapes. If it's data belonging to the object that is being abstracted, mixing by ref\by value sounds terrible. But if the data is more like the options example, mixing doesn't sound too bad to me.

 

Personally, I avoid my own by reference at almost all costs. Of course things like files and controls are already by reference. Those can't really be avoided. But I hardly ever make my own by reference classes with DVRs, Queues, etc.. Simply because they are a pain to debug. 

Message 4 of 5
(1,283 Views)

@BertMcMahan wrote:

That said, I can't really think of a good non-singleton class that would benefit from a mixture of by-val's and by-ref objects. The two AF examples you gave are WORM data. The values don't get updated after they're originally created.


"By reference" isn't "singleton".

 

We have:

1) by wire \ by reference data

2) by wire \ by value data

3) global data

 

A singleton is global, you can have multiple by reference objects of the same class. There's only 1 singleton (or it isn't a singleton).

0 Kudos
Message 5 of 5
(1,281 Views)