LabVIEW Idea Exchange

About LabVIEW Idea Exchange

Have a LabVIEW Idea?

  1. Browse by label or search in the LabVIEW Idea Exchange to see if your idea has previously been submitted. If your idea exists be sure to vote for the idea by giving it kudos to indicate your approval!
  2. If your idea has not been submitted click Post New Idea to submit a product idea to the LabVIEW Idea Exchange. Be sure to submit a separate post for each idea.
  3. Watch as the community gives your idea kudos and adds their input.
  4. As NI R&D considers the idea, they will change the idea status.
  5. Give kudos to other ideas that you would like to see in a future version of LabVIEW!
Top Authors
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

Create an "Optional" input type wrapper in the style of C++17's std::optional

Currently, we can make inputs to subVIs optional (or indeed recommended) and not wire them - in this case, the default value for the input terminal is used. By default, this is the default value for the type, but it can be easily changed to another value (at least for terminals you can easily set).

 

Since there is no "optional" type, this leads to code potentially like

Example_VI_BD.png

If -1 is always an invalid value here, this might not be so terrible. The issue becomes more pervasive with, for example, empty strings (or string constants) when an empty string or that constant might conceivably be a valid value.

 

Class objects could be an additional problem, especially if a hierarchy is considered, because you might want to wire an uninitialized child object to an Init Object method, and it would fail an equality check vs the terminal type. You might then mistakenly conclude that it was already partially/fully initialized, and carry out the incorrect processing (in this exact case, probably dynamic dispatch followed by an equality check against the specific child, then calls to a static dispatch "Init Object_internal.vi" in the parent might work).

 

We can work around this if needed by using a boolean clustered with the value, and then checking the boolean, but this makes wiring the subVI and creating its inputs more frustrating.

 

I would like to see an optional terminal type that could be checked using a primitive to indicate if it was wired by the caller or not.

Example_VI_BD.png

(Apologies for the ugly icon, and probably dubious naming)

 

 

For the draft of the proposing paper in C++ for the std::​optional type, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3672.html


GCentral
15 Comments
Proven Zealot
Proven Zealot
Active Participant

 Question: could this be done in the context of a VIM Malleable VI?   The reasons given in the other linked ideas apply only to non-inlined VIs, where the "is connected" question can vary with call site.  This idea would be quite useful for VIMs.

Proven Zealot

> could this be done in the context of a VIM Malleable VI? 

 

That is a question I have actively explored. It gets really tricky to find any sort of decent syntax. I've played around with some variations, but nothing satisfactory. It somehow involves putting a control on the panel that is a cluster of the real terminal type and a Boolean, showing only the real type in the caller node, and providing the Boolean as a constant on the implementation block diagram. It gets weird, and I haven't heard a lot of call for this feature. I wanted to have this sort of thing when I first started writing in G, and I've raised the idea several times over the years, and I generally get users telling me, "Oh, yeah, I kind of wanted that one time, but I worked around it. Not a priority." So unless I found a slam-dunk, "Yeah, that works elegantly," it's not getting a lot of mental bandwidth from me.

Active Participant

The primitive shown in the idea isn't elegant, but it is simple and functional. 

Proven Zealot

Powell: That node as drawn is meaningless. Unless that FPTerminal is outputting something other than an integer, there's no data downstream to operate on, even as a primitive. Which puts us right back to discussing how to make the FPTerm output something other than an integer. And if it can output something other than an integer (i.e. a cluster of integer and boolean), then there's probably no need for the special primitive.

Active Participant

I'm thinking of the node as a marker for the compiler when it does the inlining: replace with a False constant if the attached input is not connected, else replace with True.  It would never actually exist as such in the compiled code. This seems consistent with how other aspects VIM inputs work.

Proven Zealot

I can see how that could work. It's still really weird from a "read this diagram and understand what it does" point of view. And the node would have to be restricted to be immediately downstream from an FPTerminal to have any meaning, which would be a pretty unique requirement.

Proven Zealot

It would almost make as much sense to just say, "If there's a Boolean constant on the block diagram whose label is IsWired_<<label of control or indicator>> then on instantiation of the VIM, set the value of that constant based on the wiring in the caller."

Proven Zealot

If there was an "any type" type, the vim could check the type of the control with existing (an planned) mechanisms. To see if a control is wired, the type could be checked. This is already sort of possible, when you check if the input is an variant. But that won't work if variants are supported...

 

It won't work for outputs though...

 

A property node would make sense to me. You can create already create them for all controls and indicators. However, AFAIK they're not supported in vim.... Not sure if it's possible to allow only one property node in vim, and only inside vim. Also the CP terminals probably stop existing when the vim is instantiated. But that's all technical. From a user point of view, a property node seem to make sense.