DEV Community

Discussion on: Why are global variables bad?

Collapse
 
cathodion profile image
Dustin King

A small program with global variables is equivalent to a single object with instance variables. Just less typing, plus some semantic differences that are imposed by the programming language.

It's probably better to encapsulate the variables somehow if the program gets to be more than one file or a hundred lines or so. Or if it's important enough to unit test or use in a multi-threaded way. This is just part of the process of cleaning it up for future use, along with adding comments.