DEV Community

Discussion on: Why are global variables bad?

Collapse
 
geektieguy profile image
Oluf Nissen

What's your perspective on this: Windows apps, typically have a global "App" object. Also, sometimes there's a global thing representing something like "the keyboard" or "the screen". Are there really NO circumstances under which global variables might be acceptable? Even in a browser programming context there's usually "the window" as a global, universally accessible thing. I'm wondering if it's a little more gray than "global variables are always bad"?

Collapse
 
mervinsv profile image
Mervin

Yeah. There are still a lot of global variables being use and are still useful. But I think global variables are frequently use to declare constants inside the app. Like App object in Windows applications.

What I mean by global variables here are the one that is being declared/created by the programmer.