I’ve seen and worked with a lot of naming conventions. When I start a new development project, I always — without exception — document how I intend to name the new items I create, whether they are physical objects such as tables and fields in a database, or names used in code for objects, variables, and the like. This document is shared with the team, adjustments are made where necessary, and adopted as standard for the project or group of projects.
The important thing in this effort is consistency, and not the technique we adopt. If all single-part surrogate key fields are to end in “Key”, and all single-part varchar business key fields are to end in “ID”, then the rule must be obeyed by all developers and DBAs.
A major point of contention that seems to crop up every single time naming conventions are discussed is how and when to use an underscore. Should the field be “CustomerID” or “Customer_ID”? “ProductKey” or “Product_Key”? “SSNumber” or “SS_Number”?
CamelCase
I have a general rule: If the container (database, property window, etc) can remember case, then only use an underscore when combining an acronym with additional information, when that information comes after the acronym. This is because you can use “CamelCase“, which I find more readable.
Here are a few examples, showing how I would nornally handle underscores when case is remembered:
- CustomerID and not Customer_ID
- ProductKey and not Product_Key
- PhoneNumber and not Phone_Number
- SS_Number and not SSNumber
- ISO_Date and not ISODate
- WP_Theme and not WPTheme
- ValueEPS and not Value_EPS
And while I’m at it, avoid redundancy: VIN (Vehicle Identification Number) is not VIN_Number; GICS (Global Industry Classification Standard) is not GICS_Classification; and DG (Disease Group) is not DG_Group!
No Case Support?
If the container does not remember case, then always use an underscore to separate the parts of a name. Examples:
- customer_id and not customerid
- product_key and not productKey
- phone_number and not phonenumber
- ss_number and not ssnumber
- iso_date and not isodate
- wp_theme and not wptheme
- value_eps and not valueeps
If you can be strict about naming, project members and future generations will have an easier time understanding your code, objects, and documentation. I find that the underscore — even within a good naming system — is often used inconsistently. I also find that the underscore can make a major visual impact if used correctly. So it pays to pay special attention to ASCII character 95!
As an aside, naming conventions also play an important role in data warehouse conformity. So while it is important to have good standards, you will also need good governance to be sure that your names are meaningful and consistent.
#1 by Eric Wisdahl at June 16th, 2009
| Quote
Amen! Too often people do not set the standard for names prior to a project. Just as often, a standard is set, but revolves around technology that is not even being used. (how often have I had to use upper case with underscores because ONE of the systems in the enterprise has this constraint {and will soon be rolled off} ?)
Setting the standard and getting sign off prior to beginning is essential.
#2 by John Smith at June 23rd, 2009
| Quote
I have a question. Say your backend is Oracle database that does not support case, so you have columns like Product_Key, and your frondend is C#, so you have fields like ProductKey, now how do you map these fields? I mean you may have to modify every places that wizard generate for you.
#3 by Tod McKenna at June 23rd, 2009
| Quote
Ideally, you would adopt a convention that was consistent across the entire development environment. When that cannot be done, or if it is not practical, then my advice would be to simply confine your naming conventions to the environment. C# remembers case, so all objects and variables created in C# should use CamelCase. Because the database does not, use the underscore as mentioned above. Therefore, In your C# code, ProductKey = product_key. If you have a good multi-tiered design, many of these problems should disappear or at least be confined to code in that tier. You can also use aliases judiciously to mask (in this example) the database’s inability to remember case.
#4 by Tod McKenna at June 23rd, 2009
| Quote
Of course, you could always just adopt the least common denominator and avoid CamelCase entirely. I like CamelCase very much, so it would take a lot of arm twisting for me to abandon it to support a database version (or property sheet!).
#5 by doug k at August 14th, 2009
| Quote
i could not agree more- VIN really brought it home- now if i could only get everyone else in the office to read this article….