- Home /
Is it bad to use long variable names?
for example I declare this variable:
var EnergyTokensGoalTarget: int
While this variable's name is very helpful being so descriptive, I'm wondering if excessive use of names that long (for other variables also), ends up slowing the game down even a tiny bit.
Answer by sacredgeometry · Feb 11, 2012 at 04:57 PM
Not at all, in fact I would say descriptive variable names are very important. One thing to keep in mind is that you should try to reuse code as much as possible. So the specificity of your variables could be a good indication to how modular your code is.
r.e. performance
http://stackoverflow.com/questions/2443164/does-variable-name-length-matter-for-performance-c
Using long names is more a personal style stuff: they tell more about the variable or function purpose, but on the other hand may let some lines and expressions too long - and long lines or expressions are difficult to read (and very boring to write!)
Anyway, performance isn't affected because Unity compiles the code to CIL, an interpreted language that doesn't use names to find variables or functions (except in some very specific cases, like Invoke, Send$$anonymous$$essage etc.)
Exactly! ;) Local variable names (inside methods) are completely removed by the compiler. Only class member variable names are preserved for Reflection and RTTI. If you don't use reflection to access the variables there should be no difference. Variables are just an area somewhere in your memory. $$anonymous$$ost references are build with relative addresses.