dunbarx wrote:...whereas global variables are only available within the stack where they live, and within scripts where they are declared.
To clarify, while globals do need to be declared in each script that uses them, any script anywhere in the current LiveCode process can access them, not just within the stack where they originated. Maybe a typo where "within the stack where they live" could be "within the script where they live"?
Nonetheless, globals have gotten a bad reputation over the years. Whether this stems from the days where memory was an issue, or whether they were accused of causing all sorts of clutter is unimportant.
Memory is a minor concern, since globals can be cleared even more easily than a custom property. And because a custom property requires an object to be bound to, using a prop carries the additional overhead of a few bytes for the object to store it in, and an extra pointer to link its RAM location to the object structure. Small stuff, though, with no practical impact.
The bigger issue with globals is about code management: being globally writable by design, we need to be mindful when we write to them. Of course each of the alternatives also comes with their own trade-offs to be mindful of, so as with the rest of life we find programming offers no single magic-pony solution for all possible use-cases. Any team disciplined enough to make good use of one option can probably also make good use of any other.
The article Oliver Kenyon wrote more half a decade ago that Max linked to offers some useful guidance about the potential misuse of globals in software architecture.
As helpful as much of that article is for many of its technical explanations of our options, I'm fairly confident that if Oliver were writing it today he'd offer those with a less strident tone. After all, at the time Oliver had worked on the IDE team at LiveCode, and used globals extensively himself. This may be why no one currently on the core dev team has ever written any such a sweepingly prohibitive recommendation. Ah, the certainty of youth.
Like my old English teacher used to jokingly tell us, "Never use absolutes."
