BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Are globals really THAT evil?

Here is a very simple and crude WORM Global.  It allows a write on the first call only.  After that, any input data is ignored and the stored value is returned.

 

It has many drawbacks.  It can only hold one variable.  It uses variants in and out so that it can handle different data types.  But hey, its a start.  It would be nice if it could be made to handle multiple data objects (I hear the word OOP) and if it would not use variants.

 

Another drawback is if one attempts to write to it a second time, and is under the impression that the new value has been stored.  He would be in for a rude awakening when he finds out that the original value is still there.  It would be nice if the vi icon itself would change to reflect the data type and value of the initial setting.

 

Maybe I can work on a WORM-G creator vi, one that would create a new WORM vi on the fly.  You would give it a name and some data.  It would create a WORM vi with the name you gave it, and would use the data type of the input instead of a variant.  Not sure how to change the icon programatically.  Does scripting allow this?

 

worm.png  False case has a wire straight through.

- tbob

Inventor of the WORM Global
0 Kudos
Message 61 of 89
(10,614 Views)

I like what you guys propose, but I would like to see something different.

In my mind, WORM Globals would be created like a TypeDef control where all the values are Constants, thus you can only read them at run-time.

 

You would want something that looks and feels like the current globals, without the ability to write to them at run-time. 

 

If I have the time, I'll prepare an example.

0 Kudos
Message 62 of 89
(10,602 Views)

Ray.R wrote:

 

In my mind, WORM Globals would be created like a TypeDef control where all the values are Constants, thus you can only read them at run-time.

 

You would want something that looks and feels like the current globals, without the ability to write to them at run-time. 

 


Mon cousin du nord:

 

You are describing a Constant, not a WORM Global.  A WORM (Write Once Read Many) Global is one in which it is written to one time only.  For instance, at the beginning of a program, you might want to read an ini file (or some config file), and store some values in a global.  Then these globals could not be written to ever again while the vi is running.  Hence the term, write once read many.

 

There is a need for a constant also, one in which you set it up during development and it could only be read during runtime.  I would like to have both.

 

I agree that both should have the look and feel of a current Global variable.  Drop down a small icon on the block diagram and read its value.  Or in the case of a true WORM-G, write to it once, then read only.  It would be nice to have one Global VI that would hold many globals of different types, just like the current Global VI.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 63 of 89
(10,597 Views)

  I'm going nuts these days.

 

You are correct, mon cousin du sud..

 

Okay.. now I really like your ActionEngine.  Makes sense.  

 

Sorry about the confusion..  

0 Kudos
Message 64 of 89
(10,593 Views)

Unfortunately, the people that would most benefit from this discussion don't hang here. I don't think any of us are abusing globals anyway.

Richard






0 Kudos
Message 65 of 89
(10,561 Views)

tbob wrote:

Ben wrote:

I thought about this this week-end.

 

WORM globals - (Write Once Read Many) globals are a safe use of globals provided you and only you are the developer and you remember that you used globals and already used-up your allotment of write globals.

 

Ben


 

A very practical thought, Ben.  I would never use Globals in any way other than as constants or worm globals.  The trick is to get others, those who might inherit your code, to do the same.

 

Has anyone coined the term Worm Globals yet?  Or did I just invent something new? Smiley Surprised

 

 


Reminds me to the WOM

 

Have a nice weekend

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


Message 66 of 89
(10,556 Views)

Using scripting, you would first make your WORM design a template.

Create a new vi from that template. 

Then replace the data control of theWORM with the global control. This will be a bit 'nasty' because I think the RepNoAttrib is one of the private/scripting methods that did change between diffrent versions of LV.

You then can programatically Replace all References of the global with the WORM in the code and delete the global... 

As this weekend seems to become rainy, I propably code it... 

 

Creating an Icon should be possible. Isn't the Icon editor written in G? 

 

Felix 

Message 67 of 89
(10,552 Views)
oops
Message Edited by Broken Arrow on 04-30-2010 09:38 AM
Richard






0 Kudos
Message 68 of 89
(10,548 Views)

Update: rainy weekend over. Didn't code for this thread. Won't find the time before winter.

 

Felix

0 Kudos
Message 69 of 89
(10,490 Views)

In this message I saw some say this that I think should be quoted and remembered.

 

"I tried to solve that with a local variable, but does not work correctly"

0 Kudos
Message 70 of 89
(10,409 Views)