You can have different naming convention for class members, static objects, global objects, and structs. Some of the examples of them are as below.
_member
m_member
or in Java case, the usage of this.member
.
But is there any good technique or naming convention for function variables scope that conveys when a single variable has complete function scope or a short lifespan scope?
void MyFunction()
{
int functionScopeVariable;
if(true)
{
//no need for function variable scope naming convention
}
}
I actually encourage delegating this task to the IDE/editor you use.
No, I'm not actually talking about naming variables, that is still best done by a human. But the underlying task of such naming strategies is to show you which type of variable any one name represents.
Pretty much every IDE worth its salt can define different styles (colors, fonts, font types, ...) to different variable types (instance member, static member, argument, local variable, ...) so letting the IDE tell you what type of variable it is actually frees you from having to type those (otherwise useless) pre- or suffixes every time.
So my suggestion: use meaningful names without any prefix or suffix.
One method is to follow the guideline that the larger the scope of the variable, the longer the name. In this way, global variables get long descriptive names while scope-limited things like loop index variable can be as small as single letters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With