What is the accepted naming convention of the controls?
-
Greetings, I am new to Visual C++. I would like to know the naming conventions of the controls. For example, in the sources on this site, the button controls are called m_button1 or something. I would like to also know what p before a variable is and what b is. Thanks Rob
-
Greetings, I am new to Visual C++. I would like to know the naming conventions of the controls. For example, in the sources on this site, the button controls are called m_button1 or something. I would like to also know what p before a variable is and what b is. Thanks Rob
The Hungarian prefixes are: p = pointer, eg pu = pointer to a UINT b = boolean (Microsoft uses f instead, meaning "flag". MS uses b for byte. If you use b for boolean, use by for byte.) As for naming of controls, what I do is make the name short but descriptive. Eg, if I have a list control I might call it m_FilenameList or m_ItemList. I don't like using Hungarian for controls, but that's just my personal preference. m_listItems just seems awkward to me. --Mike--
-
Greetings, I am new to Visual C++. I would like to know the naming conventions of the controls. For example, in the sources on this site, the button controls are called m_button1 or something. I would like to also know what p before a variable is and what b is. Thanks Rob
Typically I use a modified form of Hungarian Notation. As an example a if I have a dialog with a button resource ID of IDC_APPLY and a label of Apply, I would have a tendency to call the variable m_wndApplyButton the "m_" means it is a member of the class (a dialog class in this case). "wnd" most controls are actually windows of one sort or another "Apply" which is its function and finally "Button" because it is. Note: The specifics of a Naming Convention are really unimportant. What is important is that there is ONLY ONE Convention, that it is well documented, it is supported by all users and it must be consistently applied to all projects.
-
Greetings, I am new to Visual C++. I would like to know the naming conventions of the controls. For example, in the sources on this site, the button controls are called m_button1 or something. I would like to also know what p before a variable is and what b is. Thanks Rob
The two previous responses are right on target. Both have said that the exact nature of the convention is less important than that you use one and that it be clear. I could not agree more. The Hungarian notation identifies the type of the variable: m_iNumber would be a member variable of type int, m_fNumber would be a type float. Like the other two responders, I don't use it. I do use the m_Var form to indicate it is a member variable. What also is important is that variable names be descriptive: showing what they do, what is their "purpose in life." This is purely a "code readability" issue but, with optimizing compilers, I make it a point to (for the most part) format my code specifically for readability and let the compiler worry about speed and size.
-
Greetings, I am new to Visual C++. I would like to know the naming conventions of the controls. For example, in the sources on this site, the button controls are called m_button1 or something. I would like to also know what p before a variable is and what b is. Thanks Rob
The importance of a naming convention is directly proportionate to two things: A) the amount of code you write and need to maintain/understand at a later date. B) the number of people involved in A. I program by myself for my own company, I can easily write a thousand lines of code in a day if I'm really humming. It's absolutely critical to me that I use a naming convention. On the other hand if I'm writing a little one shot utility that has maybe 10 variables in it I might just call them all x or y or something because I just don't care. It's hard to misplace a couple of variables in a one function dialog box. On the other hand for any of my commercial work there is a distinct possibility that down the road if I am successful I just might be hiring someone else to work on that same code. If it's difficult for them to understand I'm going to end up paying them a lot more so it makes sense if your cheap as well. :) Personally I do it like this: m_ prefixes any variable thats a member of a class and visible anywhere in that class (declared in the header not within a function itself). m_p denotes a member variable that is a pointer. ed in front of edit box names btn in front of button names ck in front of checkboxe names dt in front of date/timepicker control names lbl in front of static label names cb in front of combo box names rs for recordset names b for a bool n for an int f for a float str for a CString etc So for example I might have: m_btnExit, m_edSalary, m_dtStartDate, m_bIsEditing, m_pstrPassedString etc. I know at a glance what they are, what they are for and where they are declared (their scope). And most importantly of all use the EXACT same name everywhere on a large project or you will find yourself squinting at code and zoning out late at night. It's amazing how much time careful naming will save when you have a big job to do and your tired. I have wasted lots of time when I have done somthing silly like called a dialog resource edit box "IDC_DATE" and then called the variable "m_edStart" or something equally unrelated. For example I have a hypothetical edit box that is used to enter a first name, I would name it along these lines IDC_FIRSTNAME for the resource, m_edFirstName for the CEdit control variable. I don't recommend calling everything a window because thats kind of obvious and doesn't help much when you have a lot to do. It doesn't really matter how you do it, but whatever you choose to do stick with it. If your going to app