Greetings ....
For the many years that I programmed with PowerBasic DOS (2.1, 3.2 and 3.5), I needed a few global variables available throughout an entire program, usually for purposes such as program control, display/file save/printing options, security access to certain items and many other needs. These global variables were defined at the beginning of each PB-DOS program with the SHARED statement.
When using the PowerBasic Console Compiler, programmers have the option of defining global variables with the GLOBAL statement, and this is usually done at the beginning of each PB-CC program.
Now that I've taken my first baby steps with PB-CC, I have found that I do not seem to need global variables for any reason - at least the need hasn't arisen. Instead, I am creating functions (with FUNCTION/END FUNCTION) that can control various aspects of any given program much better (for me) than global variables.
Functions can return a numeric or string value just like variables, and they are always available for usage anywhere in a given program. Because of their ability to accept one or more arguments passed to them, functions be controlled in terms of what specific value needs to be returned. The returned value will in turn determine what the program is to do next.
So I wonder - are GLOBALs really necessary? If they are, then why?
For the many years that I programmed with PowerBasic DOS (2.1, 3.2 and 3.5), I needed a few global variables available throughout an entire program, usually for purposes such as program control, display/file save/printing options, security access to certain items and many other needs. These global variables were defined at the beginning of each PB-DOS program with the SHARED statement.
When using the PowerBasic Console Compiler, programmers have the option of defining global variables with the GLOBAL statement, and this is usually done at the beginning of each PB-CC program.
Now that I've taken my first baby steps with PB-CC, I have found that I do not seem to need global variables for any reason - at least the need hasn't arisen. Instead, I am creating functions (with FUNCTION/END FUNCTION) that can control various aspects of any given program much better (for me) than global variables.
Functions can return a numeric or string value just like variables, and they are always available for usage anywhere in a given program. Because of their ability to accept one or more arguments passed to them, functions be controlled in terms of what specific value needs to be returned. The returned value will in turn determine what the program is to do next.
So I wonder - are GLOBALs really necessary? If they are, then why?
Comment