LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster Type Def. vs Array of Clusters Type Def. - Best recommended practices ?

Solved!
Go to solution

Hi all, I am creating a cluster that will be used inside arrays throughout my code, of course I will need to bundle and unbundle it many times. My question is:

 

What is a better practice ? Defining the type def as a cluster then adding it into an array where this is needed ? or by defining the type def as an array of this cluster ? It seems to me that it would be better to define the type def as a cluster so when you need to bundle or unbundle it you don't need to index the array first, right ?

 

Thanks

 

Jose

Message 1 of 13
(3,333 Views)
Solution
Accepted by topic author JMotaB

@JMotaB wrote:

Hi all, I am creating a cluster that will be used inside arrays throughout my code, of course I will need to bundle and unbundle it many times. My question is:

 

What is a better practice ? Defining the type def as a cluster then adding it into an array where this is needed ? or by defining the type def as an array of this cluster ? It seems to me that it would be better to define the type def as a cluster so when you need to bundle or unbundle it you don't need to index the array first, right ?

 

Thanks

 

Jose


Agreed.

 

I seldom type def arrays but almos always type the cluster I put in them.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 13
(3,330 Views)

I would actually say that the answer depends on how you will be using the cluster. If you are defining some application cluster that will have an array of some type in it, but your application only uses a single instance of this cluster than put the array in the typedef. If you are talking about an application that will create/manage multiple items that all use the same typedef for their data, I would use an array of the clusters.

 

There really isn't a right or wrong answer to your question. The answer really is dependent on how the data is used. You should chose the best definition for your data and how it will be used.

 

Since you mentioned that you wanted to avoid using an index array one could assume you were asking if your typedef should have something Element1, Element2, Element3, etc. that would replace the use of an array. I would recommend against using this type of definition. If you will ever need to expand the application there is nothing needed if you use an array since by definition they are dynamically sized. If you predefine N elements you stand a good chance of picking wrong and therefore will need to touch the code to extend its capabilities.



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 3 of 13
(3,324 Views)

dittoes dittoes!

 

An array of Typedef is the way to go


"Should be" isn't "Is" -Jay
Message 4 of 13
(3,320 Views)

I concur.  Typdef the cluster (the array element).  Don't typdef the array itself.

 

The two types of data I would almost always typedef are clusters and enums because they are two of the more complex and/or customizable datatypes.  It would be a nuisance to have to update multiple instances of them if you ever need to modify them.  Since an array is an easy modification to its basic element (you just do a build array on the element, in this case the tydedef'd cluster), there is no need to typedef the higher level.

 

On the other hand, if you typedef'd the array, you could easily get to its basic element building block which is the cluster, but at that level, you haven't typdef'd it, so any modifications to the element requires you to modify any code that works on the basic element as well as update the typedef'd array control.

0 Kudos
Message 5 of 13
(3,310 Views)

Thanks everybody for their quick and educaded responses.

0 Kudos
Message 6 of 13
(3,306 Views)

Let me turn this around.

 

What benefits is there in type defing the array?

 

Set scrcasm mode = true

 

I can get more red dots to decorate my boring diagrams.

 

I get the opertunity to set myself up for disaster by using a type cast to get rid of those dots.

 

Set sarcasm mode = false

 

If I had a data structure that can cahnge from a 1d to a 2d to 2d as the project develops, then there may be a benefit in not having to update the icon connectors but the code is likely to break as a result.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 13
(3,305 Views)

Call me crazy, but I TypeDef both the cluster and the array.  Saves a click or two here, costs me a click or two there.

Message 8 of 13
(3,282 Views)

 


@Darin.K wrote:

Call me crazy, but I TypeDef both the cluster and the array.  Saves a click or two here, costs me a click or two there.


DONE! you are crazy. 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 13
(3,277 Views)

@Darin.K wrote:

Call me crazy, but I TypeDef both the cluster and the array.  Saves a click or two here, costs me a click or two there.


I'm curious.

 

Can you give me an example where the type def'd aray saves you anything?

 

I did type def arrays when I first learned about type def's but I am hard pressed to give an example where it saves me time or any other benefit.

 

Waiting to learn something,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 13
(3,254 Views)