views:

564

answers:

3

I found this comment in the LabVIEW instrument driver guidelines (section 6.2):

If you need more terminals than the recommended patterns, reconsider the grouping of the controls and indicators on the VI. Except for error in and error out, avoid using clusters to minimize the number of terminals. Clusters often require the user to unbundle and rebundle data from the cluster.

If National Instruments is discouraging clusters, what does "reconsider the grouping of the controls and indicators on the VI" mean?

I really like using clusters, and I think they've improved my VIs. Am I missing something?

+2  A: 

Clusters as a data type are fine. What NI is discouraging is the bundling data into clusters for the sole purpose of passing data to a sub-vi. If you have data that must be shared between numerous vis ( or sub-vis) then you should consider using a functional global, or changing your architecture to normalize your data.

Phil Brooks
Functional globals, like globals in all languages, need some care when designing a solution. In particular, they tend to break the appearance of dataflow, which can lead to some peculiar debugging issues.
Underflow
Also I think NI driver guidelines would discourage using a functional global as part of the interface of your driver suite - see 2.6, 'Design configuration VIs so they do not rely on the status or setting of another VI'.
nekomatic
Just to comment on my comment, this is not to say functional globals shouldn't be used - when they're appropriate, they're great.
nekomatic
+5  A: 

Bundling and unbundling are relatively trivial processor and memory hits, so performance isn't a worry unless you're working in a tight loop.

However, when the connector pane starts looking like a variegated porcupine, many people will start dropping everything into a "megacluster" input. While this does work (for a while), it eventually leads to a lot of unnecessary memory bloat and debugging pain, as things that aren't needed in a function still get copied around in the code.

Even worse, one can end up with different megaclusters for different VI's, and then need to translate between structures.

I usually find it best, when the inputs and outputs start getting excessive, to go back and refactor one VI into several, each with a smaller, more clearly defined function.

Underflow
+5  A: 

I think this is probably poor phrasing in NI's documentation. If it makes sense that a number of different values are written to or read from the instrument or its driver in one go then a cluster is the appropriate data type. You want to try and avoid the situation where the user has to read the data in the cluster out just so they can write it back in with one value changed. The other good general principles for using clusters, certainly in distributable/reusable code like an instrument driver, are:

  • Save the cluster as a strict typedef
  • Always bundle/unbundle cluster elements by name.

That way you can change what's in the cluster without breaking existing code.

nekomatic