Description: And why you should use it
Posted by: rkzad|
Date posted: Jun 09 2003
User Rating: 5 out of 5.0
|Number of views: 6383|
Number of comments: 1
This tutorial is inspired by MutantSquirrel and is about Hungarian notation.
Hungarian notation is a variable-naming convention. Using Hungarian notation, a programmer could take a look at a piece of your code using a variable named "szHawaii" and immediately recognize it as a string without searching all over the place for the definition of the variable. This is very helpful especially when more than one programmer has to deal with the same code. Even if you're the only one working on it, it will require less thinking on your part when you're dealing with your own code. The general principle is you add a short prefix in lower-case infront of your variable name to help show what data type the variable is.
Here is a list of the Hungarian notation conventions as given by Microsoft (Hungarian notation was apocryphally named in honour of Microsoft programmer, Charles Simonyi):
| || |
by byte or unsigned char
cx / cy short used as size
dw DWORD, double word or unsigned long
i int (integer)
n short int
p a pointer variable containing the address of a variable
sz ASCIIZ null-terminated string
w WORD unsigned int
x, y short used as coordinates
Also when you're declaring variables, you will want to keep the scope in mind (local, member, global) and whether it is static or not. To name your variables for this, right the given prefix needed, followed by an underscore, followed by one of the prefixes above depending on the data type (ex m_iNumber).
You can also combine static and member/global variables by butting the letters together, i.e. ms_iNumber.
| || |
|m_ member variable|
g_ global variable
s_ static variable
local variables don't need an extra prefix
A couple other conventions come up when declaring classes:
| || |
|C regular class (ex CBob)|
I interface (ex IDirect3D9 - a class with no member variables and no implementation)
Conventions will range from programmer to programmer and from code to code, but all are generally similar. There is no right or wrong way to do this, but you should just make sure that your code is easily analyzable. This is a really good thing to practice, and it will see how it can end up being helpful, especially when coming back to code you haven't touched in a while, and when your code is getting rather large.
Variable Names and Hungarian Notation
Showing comments 1-1
What if you want to change what type a variable is? You would have to find every single referance in the code and change it. Some more recent IDE's (well, I have noticed the more recent Borland Delphi ones) allow you to change variable names all at once, which would solve it I suppose.
You must register
to post a comment. If you have already registered, you must login
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (9 guests)