Thanks for those comments, particularly the first one. This puzzled me: I originally put the config vars, as you suggest, at the top of the script. But then I thought I shouldn't do that, because the received wisdom seems to be that one shouldn't allow proliferation of what are effectively global variables. I suppose in a script this size that doesn't matter. But actually, what this brings home to me is that I don't really understand why it is a bad idea to proliferate globals defined for the scope of the whole script. So I don't know how to balance this against the clarity advantages of having them at the top. Any comments on this topic gratefully received.
§ George Sherston | [reply] |
This puzzled me: I originally put the config vars, as you suggest, at the top of the script. But then I thought I shouldn't do that, because the received wisdom seems to be that one shouldn't allow proliferation of what are effectively global variables.
The general wisdom is that one shouldn't proliferate global state. Configuration items aren't stateful. They are essentially read-only, named constants. Non-constant global variables, particularly when they're set frequently from all over a program, can make that program wickedly hard to understand. Not so with constants.
If you want to be doubly righteous, you can use constant to prevent someone from accidentally writing to your configuration items.
| [reply] [d/l] |