Girl with Rose

“What’s in a name? That which we call a rose
By any other name would smell as sweet.”

Romeo and Juliet (II, ii, 1-2)

In team programming efforts, there is always the Naming Conventions discussion. We agree on the need for Naming Conventions but rarely agree on what these Naming Conventions should be.

We look to see what Microsoft’s Naming Conventions are. Brad Abrams has synthesized them into an easier list.  The trouble I have found with nearly every Naming Convention is forgetting to have a discussion about design time controls.

You know, the fields we drag from the tool box onto our Windows Form.  If these controls are named wisely, IntelliSense will help us in our programming efforts.

Do not use Hungarian notation.  This is usually stated early in the Naming Conventions document.  The exception I have to the rule is design time controls.  All these controls are placed in the MyForm.designer.cs file.  My code behind editing will be in MyForm.cs  IntelliSense is my best way to find these control names.

For Example, I have created the following Windows form.

From the picture we can see three controls associated with Major. The same is also true for Year, Minor and Center. Each of these controls must have a unique name. It is a mistake to leave them named Label1, TextBox1 and DataGridViewColumn1. By using a prefix, the names become lblMajor, txtMajor and colMajor. This also allows IntelliSense to be a helpful coding tool.

Just type in txt

and the TextBox controls are quickly visible.  Some people might say that business usage is the most important and the names should be something like, majorLabel, majorFilter, majorDataGridColumn.  But this does not handle the following situation well.

Due to the purchase of a third party accounting package, the word “Major” will now be replaced with the word “Account”.  Do you update every control name to become accountLabel, accountFilter, accountDataGridColumn or is just the text in the controls simply changed from Major to Account.

Regardless of the change implemented above, I can type txt and see either txtAccount or txtMajor.  With the business name first, I type major or account and hope I see the text box I am looking for.  Maybe I inherited this program from some one else and the business name is not as obvious as this example.

Bull Rose

Do not use Hungarian notation is a rule I typically follow but there is at least one good place to use it to enhance productivity.  Not all rules are valid for all circumstances.  Some rules have exceptions.

Make practical coding guidelines and naming conventions.  Do not sacrifice “workability” for some perceived “purity”.


Leave a Reply