What's wrong with Globals?
Graham Samuel
livfoss at mac.com
Mon Apr 2 17:53:12 EDT 2007
Forgive me if this conversation has ended, but my internet connection
has been in meltdown... just got back on line.
I most frequently use globals because there aren't global constants.
I use them very largely for strings containing stuff like error
messages or even very simple strings like "OK", so that I can refer
to these indirectly in scripts, thus allowing me to switch (human)
languages by redefining the globals in just one script of the
program. I guess I could have used custom property sets with exactly
the same effect, and with the advantage that I wouldn't have to
initialise them during the startup of my app, but like many others I
didn't understand these when I started, and I tend to re-use stuff I
wrote before. I guess there isn't much difference between writing
answer gcOK -- 'gcOK' is a global with a string in it.
and
answer (the gcOK of stack "allTheConstantStrings") -- 'the gcOK'
is a property of some object.
but the second statement seems to have more characters in it, since
it involves referring to the object in which the property is stored.
If there are a lot of such references, my scripts are going to get
longer.
I also use globals when I have a quantity which needs to be used in
different scripts in different stacks, i.e globally: a very obvious
point, but I really don't see what is wrong with that. I do accept
that I have to be disciplined about changing their values. I do use
properties (I tend to use these for global status stuff like 'the
soundOn of this stack'), parameter-passing and message-passing
extensively, but to me globals feel right for quite a lot of things.
I shall now wait for someone to tell me why this is a really wrong-
headed approach. I'm always willing to learn - really.
Graham
----------------------------------------
Graham Samuel / The Living Fossil Co. / UK and France
More information about the use-livecode
mailing list