01-07-2010 10:09 PM
01-07-2010 10:13 PM
01-08-2010 08:50 AM
Dennis Knutson wrote:
That's a perfectly legitimate use of local variables.
... because it sounds like you are limiting your use of locals to an initial start-up state where thre is no possiblility of a parallel thread attempting to write to the same objects.
Ben
01-08-2010 09:42 AM
secr1973 wrote:
I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them. Is there a better way to do this without using local variables?
That's from the local variable "purist" crowd. Local variables, like every other programming construct, has its intended use, and can be abused. Just like every other type of programming construct. Believe me when I tell you we've seen while loops abused. Like newspapers, don't believe everything you read.
I'm surprised someone from that crowd hasn't chimed in to say "Use property nodes!".
01-08-2010 09:47 AM
secr1973 wrote:
I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them. Is there a better way to do this without using local variables?
That's from the local variable "purist" crowd. Local variables, like
every other programming construct, has its intended use, and can be
abused. Just like every other type of programming construct. Believe me
when I tell you we've seen while loops abused. Like newspapers, don't
believe everything you read.
I'm surprised someone from that crowd hasn't chimed in to say "Use property nodes!".
I think I would say it is kind of like drinking. If you drink a lot you can become an alcoholic and bad things can happen. If you drink responsibly then everything should be ok.
Just my thought
01-08-2010 09:56 AM
smercurio_fc wrote:
secr1973 wrote:
I guess I don't really have a problem, but I keeping reading on here that local variables are bad and that you should avoid using them. Is there a better way to do this without using local variables?That's from the local variable "purist" crowd. Local variables, like every other programming construct, has its intended use, and can be abused. Just like every other type of programming construct. Believe me when I tell you we've seen while loops abused. Like newspapers, don't believe everything you read.
I'm surprised someone from that crowd hasn't chimed in to say "Use property nodes!".
After two Knight and a Knight-in-waiting approve it who's going to argue?
Who?
My alter-ego!
Property nodes are the method I use most often becuase I can push the initialize operations down into a sub-VI and keep my GUI code cleaner.
The VI labled "Init" in this diagram illustrates what I typically do.
Done alter-ego-ing!
Ben
01-08-2010 12:21 PM
I've kept quiet because of my reputation with Local Variables...
So I'll be Ben's Super-Alter-Ego and dare to say: "you can also use Property Nodes". However, if you do not abuse the use of the Local Variable, I will close my eyes and admit that they are probably more efficient than the Property Node (that's what I read from people on the "inside".
I tend to stay away from both property nodes and Locals by using shift registers. Of course, the top of the structure does have many wires running across it.. Cluster wires, of course.. 😉
01-08-2010 12:31 PM
How would you use shift registers Ray? He want to update the initial values of the controls at startup, from a file, then be able to modify those control values and save them to a file.
01-11-2010 07:04 AM
Hi Putnam,
Ooops,... sorry. I wasn't suggesting that he should use a shift register. I was saying that I use shift registers over Locals.
I will do an example and post it to illustrate what I mean. 😉
01-11-2010 07:28 AM
Local variables are far more efficient than property nodes. Why? Property nodes are typically synchronous. The node returns when the task is complete. In this case, the front panel control must be fully updated and rendered. You can make this more efficient for multiple changes by deferring panel updates, but you still need a full update of the front panel pieces you change. Local variables, on the other hand, write their values to a transfer buffer. The front panel is updated at it's next regularly scheduled time, but the variable does not block execution. If you write to the variable several times before the front panel is updated, the transfer buffer is updated, not the actual front panel. The front panel always gets your latest update. As a result of this, local variables are about three orders of magnitude faster than property nodes when setting a value. I always use local variables when I can for this purpose. However, when you have a complex GUI, it is often nice to be able to encapsulate pieces of behavior in a subVI. Like Ben, I then use property nodes.
Local variables are powerful. You can use that power to help or to hurt...