Jun-27-2019, 10:47 AM
I would like to know what are the best practices to manage variables in a complex application (ie multiple windows/menus/forms etc). I am relatively new to GUI programming so I apologize for any misconception I would have.
My issue is with variables representing data or application-wide settings that are meant to me shared between the different modules
Up to now I have found 2 approaches:
1) the variables are assigned in a common top level scope (mainwindow for ex) and variable values are passed to child widgets when needed.
This seems to be the safest approach as only the relevant variables are passed as argument to the child scope. However the values modified in the child scope must eventually be returned to update the "original" variable in the top level scope. This method looks cumbersome when a large number of variables is involved over multiple scope levels.
-or-
2) the variables are assigned in a separate .py file which is imported into each relevant module. This method is more direct, no passing arguments, no need to return anything since the variables can be directly read/modified from any scope inside the module. I personnaly do not like this approach which looks like an equivalent of global variables since the data can be accessed from anywhere inside the module without explicitly passing arguments.
As I see it, both methods have their drawbacks and i am unsure what whould constitute a "good" approach for a GUI developper. Any thoughts or recommendations?
My issue is with variables representing data or application-wide settings that are meant to me shared between the different modules
Up to now I have found 2 approaches:
1) the variables are assigned in a common top level scope (mainwindow for ex) and variable values are passed to child widgets when needed.
This seems to be the safest approach as only the relevant variables are passed as argument to the child scope. However the values modified in the child scope must eventually be returned to update the "original" variable in the top level scope. This method looks cumbersome when a large number of variables is involved over multiple scope levels.
-or-
2) the variables are assigned in a separate .py file which is imported into each relevant module. This method is more direct, no passing arguments, no need to return anything since the variables can be directly read/modified from any scope inside the module. I personnaly do not like this approach which looks like an equivalent of global variables since the data can be accessed from anywhere inside the module without explicitly passing arguments.
As I see it, both methods have their drawbacks and i am unsure what whould constitute a "good" approach for a GUI developper. Any thoughts or recommendations?