LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
altenbach

Make the default element value of arrays more useful

Status: New

Array elements can have a default value that is different from the default for the datatype. This is useful!

 

However, the use is not consistent across LabVIEW, here is a simple example:

 

 

(1) If we index into an array, and the index falls outside the current range, we get the default for the datatype ("" in this case), and not the default for the array element (which is not an empty string here!).

 

(2) However, if we add a new element skipping a few elements, the elements in between get the default value for the array element, and not for the datatype.

 

This seems inconsistent and the help pages actually confuse it even more.

 

From the help on "Index array"

 

"If the index is out of range element or subarray returns the default value of the defined data type for the array."

 

Clicking of the  default value link above says that:

 

The default value is the value used to pad the array when the array expands. For example, if you set the array index to a value beyond the defined portion of the array and enter a value in an element greater than one row past the defined portion of the array, the elements between the previous end of the array and the element you added are set to the default value.

 

As is obvious from the observations in example (2), the underlined statement seems actually incorrect!

 

IDEA: I suggest that indexing outside the range of an array should return the default value for the element (if defined).

 

In the case (1), it should return the 7 character string "Nothing" instead of an empty string.

 

(of course this change might break a lot of legacy code, not sure what to do about it)

9 Comments
Brian_Powell
Active Participant

This is not a commentary on the pros or cons of this idea, but rather an explanation of why LabVIEW behaves this way.

 

The default value is an attribute of the control--specifically in this case, the default value of the string control inside the array constant.  Expanding the number of array elements through the editor is operating on the control, so it knows how to fill in the default values as needed.

 

The default value does not propagate down the wire.  So, the array index function just sees an array of strings, and knows nothing about "nothing".  (Sorry, I couldn't resist. Smiley Happy )

 

To implement this feature, we'd have to start propagating more information down the wire. We would also have to consider how it propagates through other functions--e.g., adding two arrays of numerics, where the default values of the numerics are different...

 

default.png

This seems like a non-trivial exercise.

altenbach
Knight of NI

Thanks Brian.

 

Makes sense. Maybe it could be similar to this idea where the primitive itself gets told about the desired out of range value.

 

This would be similar to the e.g. current  " XXX string to number" functions where we can define the type and value of the output if no number is found.

 

In any case, the help is a bit confusing, because it makes no distinction between the two meanings of "default value". (and there are two different links with that text).

 

Darren
Proven Zealot

Personally, those ghost values in arrays always creep me out...I'm afraid I'm going to screw something up and accidentally get one of those values when I meant to get the default of the data type. If I find one of those arrays in code I own (or inherited), I usually re-create it to get rid of the ghost values.

altenbach
Knight of NI

> I usually re-create it to get rid of the ghost values.

 

That's where this idea would com in handy 😄

 

I agree, I typically don't like non-default default values (sic!) in array element and I am always annoyed when they show up, especially with diagram constants, I get those when I drag an existing scalar diagram constant into an array container. Now I typically first ctrl-drag the scalar to get a copy on the diagram, set the value to zero, then drag in into the array container. What a detour!

PaulG.
Active Participant

I agree with the naysayers. Too many ways a "ghost" value can pop up when you least expect (or need) it and say: "BOO!" I am afraid of ghosts. Especially in my software. Smiley Surprised

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
AristosQueue (NI)
NI Employee (retired)

> non-default default values (sic!)

 

Ah, default default default default values, how I do love thee.

 

That would be the default value of array whose array element has the default value of a class where each member of the class is the default value for its respective data type. At each level, the word "default" means exactly the same thing -- a control's default value -- but when taken collectively, it creates a bewildering spiral of defaultiveness. And if you add typedefs in there, you can add another layer of defaults between each of those. I suppose if this were an array representing mortgage loans, we could meaningfully discuss default default default default default default default Default value. 🙂

GregSands
Active Participant

And whose fault is that?

AristosQueue (NI)
NI Employee (retired)

De's fault, obviously.

Intaris
Proven Zealot

Badum.