It's all connected to your ability to design, refactor, make abstractions, encapsulate, isolate functionality and that sort of thing. There is no doubt a near-perfect way to write the program you're trying to write, and it will not have these as globals at all, but it is simply not something that you can learn directly or learn on its own. Instead it falls naturally from learning the things I just mentioned. Until you get there, you just have to make the best of a bad situation, e.g. good naming etc, and keep learning how to program.