Sep-02-2020, 05:10 AM
When writing some applications (e.g., games), one ends up having perhaps dozens or even hundreds of "global" values, of several types:
1. Predefined static values one wishes to use as "named constants"
Example: Index numbers for standard items stored in arrays or lists, or names for color values
2. Values that are static after initialization, perhaps dependent on argument or configuration file or environment variable values
Example: Terminal LINES and COLS values in a console application or a boolean variable for a debug switch argument to optionally generate debugging output
3. Values that are not static for the whole program but which need to be used at many different scoping levels
Example: The current position of a player or other object(s) in a game map
Is it better to use actual python "global" (module-level) variables, or set up a "static_vars" class to initialize and hold them (all or only some?), or some other design pattern that works better?
Thanks in advance for your advice and references.
Peter
1. Predefined static values one wishes to use as "named constants"
Example: Index numbers for standard items stored in arrays or lists, or names for color values
2. Values that are static after initialization, perhaps dependent on argument or configuration file or environment variable values
Example: Terminal LINES and COLS values in a console application or a boolean variable for a debug switch argument to optionally generate debugging output
3. Values that are not static for the whole program but which need to be used at many different scoping levels
Example: The current position of a player or other object(s) in a game map
Is it better to use actual python "global" (module-level) variables, or set up a "static_vars" class to initialize and hold them (all or only some?), or some other design pattern that works better?
Thanks in advance for your advice and references.
Peter