defining and using globals in an application

Slava Paperno slava at lexiconbridge.com
Wed Jul 6 23:47:57 EDT 2011


I don't know many programming languages, but in those I do know, I notice a
distinction between defining a variable and declaring a variable. You define
a variable when you put a value in it. You may still need to declare it
before you use it elsewhere. LiveCode keeps you from terrible debugging
headaches by requiring that you name the variable in the script where you
want to use it. In fact, LC has two options in Preferences > Script Editor
called "Variable Preservation" and "Strict Compilation Mode" that I keep
turned on. It enforces a discipline and flags your errors before they become
a nightmare. I wish LC enforced even stricter discipline, like type
checking, for example... If I didn't have to state that a variable is being
used as a global, would I remember that 6 months from now? If I forget, I'm
likely to use the same name for a different purpose, and wouldn't that be a
mess! But this may be a matter of taste. I'm grateful when my computer
catches my mistakes :)

You said "the value of that global not be available anywhere else," but the
value IS available everywhere else. You just have to declare that this is a
global variable before using it, so LC knows where to fetch that value.

S.
 
> -----Original Message-----
> From: use-livecode-bounces at lists.runrev.com [mailto:use-livecode-
> bounces at lists.runrev.com] On Behalf Of Mark Stuart
> Sent: Wednesday, July 06, 2011 11:30 PM
> To: use-livecode at lists.runrev.com
> Subject: defining and using globals in an application
> 
> Hi Slava,
> 
> My point exactly.
> You have to define it again in every stack, or substack you want to use
> the
> value thereof.
> I define my globals at the top of each stack, outside any script. But
> only
> those globals I need in that stack.
> 
> I think it is unnatural to call it a "global" and the value of that
> global
> not be available anywhere else (in other stacks), unless you define
> that
> global again.
> 
> This sets up the scenario of typing the global names incorrectly, or
> missing
> to define it where needed.
> 
> Regards,
> Mark Stuart







More information about the use-livecode mailing list