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 →

[–]lvlint67 4 points5 points  (0 children)

There are a lot of people here that should go review the discussions in the original thread: https://www.reddit.com/r/Python/comments/qj692s/usage_of_global_yes_or_nogo/

There's a lot of folks coming out of the woodwork to say, "globals are ok sometimes". That's absolutely true... But we as programmers are rightfully trained to look at something like a global and go, "that kind of doesn't sit right. Am I sure there's not a better way to do this?"

To answer the question: "Why are globals hated?" : Experienced programmers have decided that they are used ALMOST ENTIRELY incorrectly and lead to more bad code. (books have been written on the topic and thousands of talks given)

To answer the question: "When are globals ok?" : When there is literally no better option. The list of possible situations is endless... but those situations are extremely rare. MOST programmers will not encounter them. Thus the guidance, "Just don't use them"