Post Reply 
Global variable
06-26-2017, 03:09 PM
Post: #6
RE: Global variable
(06-26-2017 11:48 AM)DrD Wrote:  I like to use reserved variables in programs, as they are very efficient. For example, they don't have to be explicitly declared. They live beyond program execution. They are very useful for debugging, or further, (external), processing.

While a program is operating, the content of global variables is manageable. The content TYPE is always known. While there is no guarantee that outside influences might not, subsequently, modify reserved, (or other global variables), that content remains under program control within the program.

This is the biggest reason to NOT use (system, i.e. reserved) global variables. I am of the opinion that these variables should be left to the user for quick on-screen calculations -- much like in the days of old where scientific calculators only had a few registers to save partial computations. Programs should have their own variables; more on why below.

Quote:The data is changeable externally. (So don't use global's for constants)! Use of global variables is a programming simplification, one that all levels of programming experience can appreciate.

You can still access non-exported variables for debugging purposes using their fully qualified names.

Quote:Cyrille, can you explain a little further why the use of global variables is not a good idea, or why they should generally be avoided? Perhaps, due to system memory management issues, etc.? (Very infrequently, I have had to "Reset" the emulator, for example. I have not had to do that with the physical calculator, so far). Also, (so far), I have not encountered any downside to using Reserved variables, and I have used them frequently.

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.

Quote:An enhancement suggestion: creation of a HOME "RESTART" version of the CAS "restart" command to reset all Reserved variables to their initial value, with [options] for [A]LL reserved variables, or to omit [L]ists, [M]atrices, etc.

As usual, I appreciate your greater knowledge, and look forward to learning from your explanations!

Home "restart" seems like a good command for users; but as a programming command I would probably never use it (again, to preserve the user's data/settings).

I do not speak for Cyrille, of course, or anyone else for that matter; just my 2 cents.

Graph 3D | QPI | SolveSys
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)