There are any number of naming conventions and coding standards. Each have their values and issues. This is the pattern I created but as it is important to stay flexable and learn new patterns as new ideas come along.
I started developing software with MS Visual Basic 2.0, back in 1993. So my naming conventions came from the Hungarian notation. However a few years later I found that this convention was not quite right for me. It was with the release of VB 4.0 in 1995 that I developed the "Rose Variant" on the Hungarian form. Not much changed. However I believe I made it easier to recognize the objects by this new convention. You see human beings are primarily visual creatures and we can interpret information visually much quicker than we can read. (Yes I understand that reading is a visual medium as well)
The Rose Variation is simply:
- Variables have a single character lower case prefix.
- Database objects have a two character lower case prefix.
- All other objects have a three character lower case prefix.
- Module level variable have a lower case "m" prior to the object prefix
- Global level variables have a lower case "g" prior to the object prefix. Note: Do not do this as it is a bad pattern to expose a variable to the entire project.
Recently I posted on several tech and development sites asking about naming conventions and if they still have a value. Because I have been using these conventions for over a decade I wanted to insure that I was not holding on to old patterns just because that is the way I have been doing so for the past years. Software development is a relatively new profession and I believe that it is important to keep up on new processes and well as new technologies. After a week of reviewing the various conversations I came away with the thought that there is still a strong value for naming standards. My variant is not the absolute answer, just one idea. What I do strongly suggest is that you find a pattern that works for you and stick with it. Over time you and other developer that have to work with your code with appreciate the consistency.
There were some who spoke that naming conventions are no longer necessary with the current abilities of IDEs. Most allow you to mouse over the object to get the details including data type and the current value. However I felt that this method of thought missed out on why I developed the Rose Variant in the first place. The ability to scan a page of code and instantly know what type of object you are looking at has been a great help for me.
For example: What is this object "UserValue" (yes it is a bad name) Is this a string or a numeric or even a full object? (yes, I know that in .NET all items are objects, let's not get picky here.) But if it was labeled as "iUserValue" or "sUserValue" then you could know instantly that it is a integer or a string.
There is, of course, some issues with the Rose Variant in that some objects will have the same prefix. eg: Single, Short and String, or Date, Decimal and Double. While I will agree that this is not perfect, I have used this pattern for over a decade and it has served me well.
Here is a listing of the differences between the two conventions. This list is not complete, and I welcome any thoughts on this pattern.
Variables:
Object | Hungarian Prefix | Rose Prefix |
Boolean | bln | b |
Byte | byt | b |
Char | chr | c |
Date | dat | d |
Decimal | dec | d |
Double | dbl | d |
Integer | int | i |
Long | lng | l |
Short | srt | s |
Single | sng | s |
String | str | s |
Database Objects:
Object | Hungarian Prefix | Rose Prefix |
Field | fld | fd |
Index | idx | dx |
Query | qry | qy |
Table | tbl | tb |
Recordset | rec | rs |
Connection | con | cn |
Command | com | cm |
DataSet | dst | ds |
DataReader | dar | dr |
DataAdapter | dap | ad |
These objects are the same for the Rose convention as the Hungarian standards.
Controls and Objects
Object | Hungarian and Rose Prefix |
Form | frm |
Check box | chk |
Combo box | cbo |
Command button | cmd |
Dialog | dlg |
Grid | grd |
Image | img |
Label | lbl |
List Box | lst |
Menu | mnu |
Option Button | opt |
Picture Box | pic |
Scroll Bar | scr |
Text Box | txt |
Timer | tmr |