I’m trying to clean up the code of a game I’m creating. From the beginning, I have put relevant functions inside a covering object. For example, the initialize function can be accessed at Init.initialize().
However, for this and other objects, I’d like to use types and then creating instances of them. For example, I have a Settings type which holds some settings of the game. The Settings should be a type, while an instance should hold the actual setting values.
Now how should I best name the type and how should I then name the instance, especially when I only have one instance? If I name the type Settings, how could I best describe the instance in the form of a variable name?
The best naming convention is one that can be read after six months of not looking at the code.
In many cases hungarian notation doesn’t make sense unless you remember what you meant.
For the settings object, call the prototypal object
and call the instances
because you (and anyone else reading the code) will understand what an instance of SettingsObject will contain, and know what the
settingsvariable holds. If you need a longer name, use a longer name, there’s no penalty for being descriptive during development.ie.
UnitMouseClickListeneror any other name that makes sense.After development you can always go back and minify code for production, but that’s only after you’ve ironed out all the kinks. Might as well be able to read your code while you’re writing it.