07-17-2009 10:44 PM
I have been studying the QSM-PC located at http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/. It uses a lot of unwired output tunnels on case structures, and uses the "use default if unwired" checked. For an array, it turns out the default value is a valid array with zero elements, and this is crucial to make this particular vi work. Is it common practice among "professional" programmers to use default values this way?
07-17-2009 10:57 PM
I guess you could say that leaving the tunnel set to "use default if unwired" is common, though I think no more/less common than not leaving it set that way. Of course, depending on the structure it's that way by default. For instance, with the event structure it's that way by default, but not for case structures. Ultimately, whether or not you should depends entirely on the situation.
And it also depends on whom you consider a "professional" programmer.
07-17-2009 11:16 PM
I'll use default if unwired only for very specific instances. For example, a stop button event will have a true constant wired to the tunnel to stop the while loop. All other event cases would use the default of False since I wouldn't want to stop the while loop for them. It saves wiring up a bunch of false constants.
But in general, Using Default if Unwired could lead to bugs. Suppose you add an new case to a case structure but forget to wire up some data to the tunnel. With Default if Unwired, your code will not be broken, and the VI will run using the default data even though that wasn't what you intended. It may take a while for you to debug your application to figure out why things are not happening as expected. For example, a VISA reference works for a while and then stops working. Why? Because the valid VISA reference got lost when the new case ran and set it to a default value.
If you don't use Default if Unwired, then your run arrow will be broken. That will force to go find all those instances of unwired tunnels and force you to either wire them up or explicitly wire a constant to it. Basically it makes you find and make a decision on each tunnel rather than giving you a chance to forget about one accidentally.
07-18-2009 12:20 AM
I agree with not leaving the wires to default values... you could always connect the wires from left to right in case you don't want to change it. And if you are changing it from something else, to default, you might as well do that using a hidden control, rather than "use default if unwired".
I'd sumarize the above as follows
07-18-2009 07:35 AM
I was taught that letting tunnels give default values was bad practice and I've come to agree that it is. I'll add one thought to what was already said - explicitly wiring each tunnel tells the person that inherits your program that you thought about the data. It's the same with those pesky coercion dots; casting to the expected data type shows that you recognized the mismatch and (presumably) decided that it wasn't an issue.
I let my state machines do this to stop the loop, but I HATE structures that have it enabled by default.