Naming conventions for form Controls? i.e. btnExit vs. frmExit....HELP
Hi there - we are trying to come up with some standard naming conventions for our controls. I was taught to prefix the name with the control type.
Ex. Exit Button would be btnExit
Ex. Name Label woulc be lblName
I have also seen prefixing the control name with "frm" Ex. frmName.
I'm not sure where the industry is moving....but would greatly appreciate some feedback on this.
Thank you!
Kelley Bryant
That's called Hungarian notation, and Microsoft stopped recommending it about the time the guy who came up with it stopped working there. I do use it still sometimes for controls, but overall the recommendation is not to use it anymore.
Like I said, although it's not generally the 'done thing', I use Hungarian notation for controls, because if I have a button called btnAction, I'm likely to have a label called lblAction, and perhaps even an Action class, which I'm likely to call action.
Hungarian notation was invented ages ago, when the development tools were just text editors and compilers. You hade to remember the types of your variables yourself, so you added abbreviations of the types as prefixes. You had b for bool, f for float, d for double, p for pointers, lppsz for far pointers to zero-terminated character strings etc.
That notion actually went out the window about 15-20 years ago with object-oriented programming - instead of a fixed number of types, now you can have thousands of classes. How do you prefix String, Stream and other classes that begin with Str differently? How do you do good prefixing when dealing with polymorphism?
Besides, the current modern tools let you see the types without having to use prefixing. Use readable well-descriptive names for new projects, but stay with prefixing for older systems that you are maintaining.
I use this.
textName
labelName
treeViewLibrary
groupBoxOption
optionTextName
optionLabelName
optionTreeViewLibrary
When it comes to controls added to form the biggest task is finding it not determining its type. Intellisense will tell you the type of the control, but it will not aid you in finding/jumping immediately to your controls without a custom naming-convention.
Hmmmm....
Maybe, a feature to group intellisense listing into 2 parts is in order. One group for anything added to the container and another one for the container.
JRQ at 2007-9-9 >
