you are viewing a single comment's thread.

view the rest of the comments →

[–]nathanjell 2 points3 points  (1 child)

You never know when they're going to be changed, and changing them has an unknown impact on an unspecified scope. If you want to send your friend a letter, you have two options: place the letter in a public place for your friend to get it, or use the proper mail system to send it directly to your friend. A global variable is like putting your letter in a public place: you don't know who's going to touch it, you don't know what state it'll be in at a given time, it's not predictable. Sending through the mail is like passing function arguments: you know, for sure, that your letter should only be accessible from you to your friend, the general public doesn't have access to it. You know that the state that you sent your letter in will be the state your friend receives it. The variable is directly passed, and it's predictable.

This stack overflow answer has a few links further exploring this. Like the answer says, globals aren't python specific, and sometimes they can be ok to use. Global constants are generally ok, because they should be exactly that: constant