Keith Devens .com |
Friday, August 29, 2008 | ![]() |
| C++ is history repeated as tragedy. Java is history repeated as farce. – Scott McKay | ||
Naming conventionsThis page could stand to be organized more neatly. Variables:class data: d_foo unless your language has a special character for this, like Ruby does Normal variable names should be lowercase, separated by underscores. I've never liked hungarian notation, though I can see a benefit to having things like foo_p, foo_pp, etc. to indicate the level of indirection... MAYBE. Function namesIf a function name can be named in a verb-noun style, that is to be preferred. So, getConnection, validateLogin, buildMaxHeap, etc. Otherwise, if there's no appropriate verb noun relation, use lowercase words with an underscore between them, such as heap_sort, max_heapify, etc. Database tables:Plural, capitalized words separated by underscores: Items Etc. For tables that express a relation, I've found names like the following work best: Item_Categories (Singular_Plural) Database fieldsSimilar to table names. Initial uppercase words separated by underscores. So, User_Id, Entry_Text, Node_Title, etc. Foo_Name should uniquely identify the row, at some level of uniqueness (say, given a certain Creation_Date) while Foo_Title is guaranteed no level of uniqueness. Don't have Comment, have Comment_Text, don't have Email, have Email_Address. Usually, some indication of the type of the field will be in the name. So, Creation_DateTime, or Creation_Date if it's just a date. Keep in mind that that's Creation_DateTime, and not Created_DateTime. Fields are nouns, and should almost never be verbs. Do not do things like sid, pid, uid, etc. User_Id is much more readable, and can specifically refer back to the Users table to make it obvious what the foreign key refers to. Common shorthandsI always put some type information in my database field names, such as "Id", "DateTime", "Text", "Description", "Number", "Name", etc. Id means "unique numeric identifier", while name means "unique textual identifier". Here's a list of abbreviations I'm going to start using:
MiscType namesFor instance, in C++, for typedefs. Initial capital. Integer, Foo, etc. Keep in mind that classes define new types, so class names should be initial uppercase as well. ConstantsEnums, etc. ALL_UPPERCASE_SEPARATED_BY_UNDERSCORES FinallyIf something refers to an acronym, don't change your naming conventions for it. escapeHtmlCharacters instead of escapeHTMLCharacters. Page last edited: February 20, 2004 (utc) |
IndexA B C D E F G H I J L M N O P R S T U V W X All pagesABC
DEFGHIJLMNOP
RS
T
UVWXGenerated in about 0.042s. (Used 4 db queries) |
