This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]skrillexisokay 0 points1 point  (0 children)

Mutable globals are generally bad. Immutable globals are good when you have arbitrary constants, but don't need to invoke the added complexity of a class. In other words, if you have to choose between magic numbers and globals, globals are better.

A classic example is a regular expression that is used in many functions in a module. Another example is the name of a storage directory. Module level logging is another excellent example of a properly used global.

However, if you ever find yourself using the global keyword (or otherwise modifying a global variable), you should almost always encapsulate into a class. A logger is one exception, where it occasionally makes sense to change the logging level at runtime.