DEV Community

Discussion on: Are global variables bad?

Collapse
 
lexlohr profile image
Alex Lohr

I think you're answering the wrong question. Global variables themselves are not bad. Spamming the global scope is, because you'll have stuff bleeding out of your scope or even worse affect other parts of a system.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Again, same problem, define "global" scope. Module scope is often restricted to module. Languages like C++ offer namespace scope as well. Top-level variables in Python don't affect the scope in sub-modules.

Sure, if you're sticking everything into one scope, that's a problem, but I don't it matters what scope that is.

Collapse
 
lexlohr profile image
Alex Lohr

Same difference. It's not about global variables, its about being mindful what to expose.

Thread Thread
 
mortoray profile image
edA‑qa mort‑ora‑y

Well yes, but that's the point of my article. To expose the ideas behind what "global" might mean to draw a learner's attention to the real issues at play.