Strict Compile Mode
Peter Haworth
pete at lcsql.com
Fri Oct 12 12:29:16 EDT 2012
On Thu, Oct 11, 2012 at 11:37 PM, Guglielmo Braguglia <
guglielmo at braguglia.ch> wrote:
> Hi Pete,
>
> if you declare a variable "global",the variable IS GLOBAL FOR ANY STACK
> and is "*persistent*". This means that the variable and its value exist
> regardless of the stack that created. If you liketo see do just a simple
> test ...
>
Wow, so a global declared in one stack can be accessed by a completely
different stack, even if the declaring stack is not in memory. That seems
like a recipe for potential disaster, especially if you are writing plugins
that are used by customers to access their own stacks.
> ... create a stack and create different scripts (e.g. some scriptfor some
> buttons). On the different scripts define "local" variable on the TOP of
> the script, before handlers. Assigns them a value. Now, if you insert some
> breakpoints (on the different scripts) you will see, still looking into the
> "Variables" TAB, that, when the script stop because reach the breakpoint
> (so the script is the current script), you will find the local variable of
> the script with the correct value.
>
I use script local variables a lot and often instead of global variables.
A script local variable plus a set of handlers to read and write from it
seems a lot easier to deal with than global definitions in every script
that needs them, especially now I know about the cross-stack global
availability issue mentioned above.
I've also taken to using script local variables/access handlers instead of
using custom properties in locked stacks so users can't change the values
of critical information by simply bringing up the Inspector window. I
still find it odd that password protecting a stack prevents access to its
scripts but not its custom properties; there at least ought to be an option
to apply password protection to custom properties.
>
> Please note that, also if this rules remain valid, the behavior of
> LiveCode is different if your "Strict Compile Mode" is ON or OFF !!! ...
> and this creates more confusion !!!
>
> With "Strict Compile Mode" ON ... you are obliged to declare the variable
> and LiveCode verify the "collisions" and give you error if one local have
> the same name of a global, BUT, if "Strict Compile Mode" is OFF, LiveCode
> don't verify the "collisions" and the same variable can be a local or a
> global depending on whether you declare it "global" or not :o ... and this
> is really ridiculous !!!
>
That's the crux of the question I posted in response to Mark's post. The
whole implementation of globals in LC is really strange. Especially since
it appears that LC "knows" about a global as soon as it is declared - why
then force people to re-declare them in every script that addresses them.
I rarely use globals now but "rarely use" will change to "never" pretty
quickly!
>
> Hope this clarify the situation ... :-)
>
Yes, thanks Guglielmo.
>
> Guglielmo
>
More information about the use-livecode
mailing list