Dave's Brain

Browse - Programming Tips - How can I reduce the number of global variables in a codebase I inherited?

Date: 2017may5
Language: any

Q.  How can I reduce the number of global variables in a codebase I inherited?

A.  You can convert a global variable into a global read-only function.

For example if you have this javaScript:

var gMyGlobal = 123;
You can change it to:
function getMyGlobal() { return 123; }
Its still global but you know it isn't being updated. There are many other techniques.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.