08-25-2021 11:10 AM
One of my cow-orkers needed to convert an array of 4 elements into a cluster of 4 elements.
He tried the "Array to Cluster" function, but it didn't work (because he hadn't set the cluster size).
So instead of looking up the help for the function, he just hacked away, ending up with this:
Not terrible, but not nearly as clean as it ought to be.
The problem is when you multiply this by every time any of them writes any piece of code.
Does anybody have any ideas on how to re-program cow-orkers so that they actually try to make good code?
08-25-2021 11:27 AM - edited 08-25-2021 11:28 AM
Well, the here advantage is that the resulting cluster correctly corresponds to the typedef cluster, while a plain array to cluster would give you a generic naming scheme.
My cluster contents are almost never of homogenous datatype, so I would actually use a bundle by name and pick the elements that need to be replaced with the values from the array. "by name" cluster functions are beautifully self-documenting (as long as the elements have good naming 😉 ).
08-25-2021 11:39 AM
Maybe the "array to cluster" should have an optional cluster input on top, which, when wired, would define the size and datatype and break the wire if the array does not match in datatype or if the cluster is of mixed type. Maybe a similar idea already exists...
Note that if the array has 4 DBLs and the cluster typedef also has 4 DBLs, a simple typecast will do the trick, properly naming the output elements:
08-25-2021 11:45 AM
@paul_cardinale wrote:
One of my cow-orkers needed to convert an array of 4 elements into a cluster of 4 elements.
He tried the "Array to Cluster" function, but it didn't work (because he hadn't set the cluster size).
So instead of looking up the help for the function, he just hacked away, ending up with this:
Not terrible, but not nearly as clean as it ought to be.
The problem is when you multiply this by every time any of them writes any piece of code.
Does anybody have any ideas on how to re-program cow-orkers so that they actually try to make good code?
I actually like this because it is pretty explicit in its conversion, but that's besides the point. I think that experience is probably the best teacher here. We all have moments when we do something a little Rube-ish because we are not aware there is a much simpler way to do this.
This is where you come in. Unfortunately, this is a problem probably only an experienced LV programmer like yourself can remedy. Simply put, every time you see something like that, you'll have to show him there is a better way to do it, so he can learn from your experience. I wish I had someone like that, but I am one of the most experienced LV programmers where I work, so nobody helps me; I end up helping everyone else (when I can). I suspect there are better ways to do some stuff than I am currently doing, but there's no one to turn to for me.
08-25-2021 12:15 PM
@altenbach wrote:
Maybe the "array to cluster" should have an optional cluster input on top, which, when wired, would define the size and datatype and break the wire if the array does not match in datatype or if the cluster is of mixed type. Maybe a similar idea already exists...
Note that if the array has 4 DBLs and the cluster typedef also has 4 DBLs, a simple typecast will do the trick, properly naming the output elements:
i would prefer if they made "Array to Cluster" smarter so then when you wire the output, it looks at it an adjusts its size.
08-25-2021 01:17 PM
Not really helping your concern here, just voicing my thoughts on alternative implementation,
Since the cluster contents are all numeric and it just simple as named elements, I would have approached this with an array of numeric and a string array containing the corresponding channel name/label for the numeric array. I do agree that every time you need to get a specific element data, you need to look up its position on the string array and then index it from the numeric array.
08-25-2021 01:46 PM - edited 08-25-2021 01:48 PM
@paul_cardinale wrote:
i would prefer if they made "Array to Cluster" smarter so then when you wire the output, it looks at it an adjusts its size.
I've voiced that thought before - but it's been pointed out that clusters dont change size at runtime, arrays can - so I too use the typecast (it's elegant beautiful and easy to read, I plan my cluster structures to use this too if they are going to be big).
As for re-programming Cow-orkers, I'm sure sometimes they'd like to reprogram you to give them training instead of moan, and to let them know when they've done something right. (I'm sure you do really Paul, just looks like you're going through a tough patch at the moment 😉)
James
08-25-2021 01:50 PM
I would say proper training and regular code reviews. Array to Cluster is a fairly basic primitive, to have a coworker working on production software who has never used that before... the thought kind of irks me, not gonna lie.
BUT, then again, take another super common primitive, Compound Arithmetic. I just learned a couple weeks ago that you can invert the inputs. I know I have code out there that would look way cleaner had I known this from the get-go. It never came up when I got trained, or in any code reviews, or by looking over legacy code. I never even noticed it when skimming the right-click menu to change the mode. I only learned about that from this forum. Was looking at an uploaded VI for a completely different thing, and saw it and was like "hoooooold up..."
Both myself and your coworker would have been fine if we had just read the Detailed Help for the function the first time we used it. In that regard, we both could use a lesson in RTFM, you could say.
Bottom line, you don't know something until you do. Hopefully now that it's come up, your coworker 100% knows how to set up Array to Cluster.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
08-25-2021 02:26 PM
In regards to the Array To Cluster mess...Go give this idea a kudos: Allow Array to Cluster Type. In the comments, AristosQueue recommends just using Coerce To Type.
08-25-2021 03:52 PM
@crossrulz wrote:
In regards to the Array To Cluster mess...Go give this idea a kudos: Allow Array to Cluster Type. In the comments, AristosQueue recommends just using Coerce To Type.
I could make an XNode that does that.