J
January Weiner
Hello,
I have the following problem. I had a script that contained only one
global variable which was called $DEBUG. I just used it to print out
various think or do some checks in debugging mode
print "number of objects $n_obj\n" if $DEBUG ;
check_sanity if $DEBUG ;
The program grew and now I splitted it up into several modules.
Question: what to do with the debug variable?
* I could make it local to all of the functions, but I would really hate
passing it through to each of the functions separately. Firstly, IMO this
is one of the few cases where global variables are justified, and second,
this would require me to make hundreds of modifications in the code.
* I could make it a global variable in each of the modules, and create a
function that switches on the debugging for one module only. This would
have the advantage that I could specify which module to debug.
Disadvantage is that I need to remember to switch it on in every module
if I want to switch it on globally.
* Finally, I could make a separate module with generic tests for sanity and
printing warning messages, and that module would hold the only instance
of the $DEBUG variable. Again, many modifications in the code required.
Of course, I can imagine that there are gazillions of other ways of doing
that, and that there are specific modules that do precisely what I want.
What route would you recommend?
Regards,
January
I have the following problem. I had a script that contained only one
global variable which was called $DEBUG. I just used it to print out
various think or do some checks in debugging mode
print "number of objects $n_obj\n" if $DEBUG ;
check_sanity if $DEBUG ;
The program grew and now I splitted it up into several modules.
Question: what to do with the debug variable?
* I could make it local to all of the functions, but I would really hate
passing it through to each of the functions separately. Firstly, IMO this
is one of the few cases where global variables are justified, and second,
this would require me to make hundreds of modifications in the code.
* I could make it a global variable in each of the modules, and create a
function that switches on the debugging for one module only. This would
have the advantage that I could specify which module to debug.
Disadvantage is that I need to remember to switch it on in every module
if I want to switch it on globally.
* Finally, I could make a separate module with generic tests for sanity and
printing warning messages, and that module would hold the only instance
of the $DEBUG variable. Again, many modifications in the code required.
Of course, I can imagine that there are gazillions of other ways of doing
that, and that there are specific modules that do precisely what I want.
What route would you recommend?
Regards,
January