Post Reply 
Global variable
06-26-2017, 04:02 PM
Post: #7
RE: Global variable
(06-26-2017 03:09 PM)Han Wrote:  When several programs start using the same reserved variables, and those programs should happen to call each other, then you can easily imagine the mess that could result. But the other (bigger) reason for avoiding them is if a user makes frequent use of these variables for their own quick calculations, then your program could very well destroy their data. My personal philosophy is that all programs should never touch a user's data and leave every global variable, setting, flag, etc. as they were unless the program is designed to explicitly modify the user's data and/or system settings.

Programmer's willing to use global's must consider the consequences. What you see as a pathway to trouble, I see as potentially added value. Every program step must be considered, if there is a reasonable expectation for success. Global variables are no different, and is yet another tool that can offer efficiency. My personal philosophy is, I see greater value in the global features, and no more risky than a myriad of other existing commands or functions.

I agree with your personal philosophy, and see no contradiction between us, where you say, " ... unless the program is designed to explicitly modify the user's data and/or system settings." Globals imply that there is a design to explicitly modify them, (or not). The debug advantage, or post processing advantage, and no requirement to declare them 'efficiency', are all good reasons to justify globals. I have come up with many programs, some just created in passing, or for examples, and some more robust that are in my master program list, that use globals exclusively, or in a mix combination with locals. To date, I have not seen any ulterior consequences, perhaps other than my own development pains, but nothing in the final work, that use of globals made into a mess.

Other than fear of ambiguous scenario's that "could happen," are there any tangible reasons not to use globals, that you can think of? Sure, you can create a program, and destroy the global data content it relies on, but such a program still works as you designed it. Thus its not a tangible reason to blame the use of global's for those consequences. The same can be said for any other aspects of a program structure. A program is only as good as its actual design, warts and all.
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
Global variable - Powersoft - 06-25-2017, 06:56 PM
RE: Global variable - DrD - 06-25-2017, 07:46 PM
RE: Global variable - toml_12953 - 06-26-2017, 12:27 PM
RE: Global variable - DrD - 06-26-2017, 11:48 AM
RE: Global variable - Han - 06-26-2017, 03:09 PM
RE: Global variable - DrD - 06-26-2017 04:02 PM
RE: Global variable - Han - 06-26-2017, 08:29 PM
RE: Global variable - DrD - 06-26-2017, 09:04 PM
RE: Global variable - DrD - 06-27-2017, 11:32 AM

User(s) browsing this thread: 1 Guest(s)