Rather than go back through my libraries and adding a “debug” flag parameter, I thought that once a debug flag (0/1) was read on the command line of my application, a ref could be set once and then accessed by any function that needed to do something if the debug flag is set.
Is that a reasonable way to handle parameter-less debugging, or is my thinking too much like having a “forbidden” global variable?
Thanks.
A global for this sort of thing is fine, although using a ref to store it isn’t really appropriate because then you’d need to do all your logging in a transaction (ie. within a
(dosync)).Since you are unlikely to really care about race conditions on your ‘logging-enabled’ it doesn’t need special protection. You’d mark this variable with ear-muffs to signal it has special meaning….
Something like this would be fine:
Note that by defining the
*debug-enabled*flag dynamic you can switch on debug for just parts of your code. In this example, imagine that all the functions used the(debug)functions mentioned above. You have*debug-enabled*set to false, but you’d like to turn it on just for(my-problematic-func). You can re-bind the flag just for that call like this: