2 ms·
Perhaps they are minor if there's one or two global variables. Once they're used liberally and there's plenty of them, the resulting bugs can become so elusive
by V-2 8y ago
Perhaps they are minor if there's one or two global variables. Once they're used liberally and there's plenty of them, the resulting bugs can become so elusive it can drive you mad.
A bug can be extremely hard to replicate, because it only arises from a very specific sequence of events that step-by-step flip the globals into an overall invalid state. And it's virtually impossible to determine "whodunnit".
It's a perfect recipe for "the app sometimes crashes on Thursdays" scenario.
- mpartel 8y agoAh, I meant to reply specifically to the command line flags use case. For most other uses of globals, I fully agree.
- V-2 8y agoAh, then I misunderstood you, sorry. Of course this is a bit of a red herring anyway... As the original commenter remarked already, command line flags may be stored globally (eg. as read-only fields), but won't - and shouldn't - be variables. They're only given once, and their values aren't going to change throughout the program's running time. So they're essentially constants, which is fine.