When naming variables there are many different methods you can use. By far the best and most wide-spread method is called "Hungarian Notation". This involves prefixing names of variables with a short character(s) representing the datatype of the variable. Coders all over the world use this type of notation, so if possible, it is best to use it because it will be alot easier for anyone else picking your code to understand.
Here are some examples:
Numbers
// This variable is an integer, and is involved in some counting procedure
int iCount = 0;
// A floating point number for measuring height
float fHeight = 0.0f;
So when you come across these 2 variables in your code you should be able to quickly and easily identify what type they are and what purpose they have.
With numbers types it is also common for people to use the "n" prefix, which simply means number. So the previous 2 examples would become:
int nCount = 0;
float nHeight = 0.0f;
But i dont like that way as much because you cant quickly tell which type the variable is.
The usage of nHeight makes it easy to change the type of a variable later on in your code, imagine you want to change from a int to a float. If your variable is iHeight, everywhere in your code that will need to be changed to fHeight. Using a standard nHeight (number) will mean that you only need to change its type definition.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.