KBD

Keith Devens .com

Saturday, May 17, 2008 Flag waving
Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.... – Alan Perlis

Naming conventions

This 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
s_foo for static class data - I think Ruby has a special character for this as well

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 names

If 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
Weblog_Entries
Referrers
Categories

Etc.

For tables that express a relation, I've found names like the following work best:

Item_Categories (Singular_Plural)
Weblog_Entry_Categories (Singular_Plural)

Database fields

Similar 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 shorthands

I 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:

CurrentShorthandDescription
Id Id "unique numeric identifier", as in Weblog_Entry_Id
Name Name "unique textual identifier", as in "Wiki_Page_Name". However, a name can be unique within some other determiner... such as a name unique within the Creation_DateTime
DateTimeDTDate + Timestamp
NumberNumAn integer. Revision_Number
TextTextA long text field. Such as Weblog_Entry_Text or Revision_Text
DescriptionDescRevision_Description
TimeZoneTZNot currently using this, but because MySQL doesn't store time zones, I have to make this a separate field
TitleTitleWeblog_Entry_Title
Boolean or FlagBAllow_Comments_B. I don't currently use a Boolean or Flag modifier, but I probably should be
TypeTypeOnly really useful for "enum" fields. Otherwise you should have something like Foo_Type_Id to indicate it's a foreign key relation

Misc

Type names

For 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.

Constants

Enums, etc.

ALL_UPPERCASE_SEPARATED_BY_UNDERSCORES

Finally

If something refers to an acronym, don't change your naming conventions for it. escapeHtmlCharacters instead of escapeHTMLCharacters.


Page last edited: February 20, 2004 (utc)

Index

A B C D E F G H I J L M N O P R S T U V W X

All pages

A

  1. About
  2. Acno's Energizer
  3. Artificial Intelligence
  4. ASP.NET
  5. Atom

B

  1. Bash
  2. Belief systems
  3. Bookmarklets
  4. Build tools

C

  1. C and C++
  2. C#
  3. C++ Reference
  4. Calvinism
  5. Cars I want to consider
  6. CGI
  7. character sets
  8. Chess
  9. Christian Reconstruction
  10. Christian Resources
  11. Chronicles of Narnia
  12. Color tools
  13. Computer Science
  14. Cornelius Van Til
  15. CSS - Cascading style sheets
  16. CSSTabs

D

  1. Database
  2. Differencing programs
  3. Documentation standards
  4. Downloads
  5. Dualities
  6. Dvorak keyboard

E

  1. E-mail me
  2. Eclipse
  3. Eiffel
  4. Emacs
  5. Evolution
  6. Extension languages

F

  1. File extensions
  2. Firefox
  3. Formation: web form automation library for PHP
  4. Forth

G

  1. Greg Bahnsen
  2. GUI Toolkits
  3. Guns

H

  1. Hex editors

I

  1. Important articles or essays
  2. Installers
  3. Internet radio stations

J

  1. Java
  2. Javascript
  3. jEdit

L

  1. Linux
  2. Lisp
  3. Logical fallacies
  4. Lua

M

  1. Markup
  2. Miscellaneous Links
  3. mod_rewrite
  4. Movie theaters
  5. My comment policy
  6. My essential programs
  7. My resume

N

  1. Namespaces
  2. Naming conventions
  3. New Years 2000
  4. N^2 sort comparison

O

  1. Open Source License
  2. OPML

P

  1. Perl
  2. Philosophy
  3. PHP
  4. PHP Calendar (version 2.3)
  5. PHP XML Library, version 1.2b
  6. Pictures
  7. Postmillenialism
  8. Presuppositionalism
  9. Programming Fonts
  10. Programming languages
  11. Programming Resources
  12. Punta Cana
  13. Python

R

  1. RDF
  2. REBOL
  3. Reflex game
  4. Regular expressions
  5. Religion
  6. RFCs
  7. Robot Exclusions
  8. Roman Catholicism
  9. Ruby

S

  1. Scala programming language
  2. Science
  3. Shorthand
  4. Skydiving, August 28, 2000
  5. Software I've written
  6. SPAM
  7. SQLite
  8. StructuredText

T

  1. Tabs vs Spaces
  2. Tcl/Tk
  3. Tea
  4. Text Editors
  5. TextDrive
  6. The Big Bang
  7. The naked street
  8. Theonomy
  9. Tools of communication

U

  1. Unicode
  2. URL Design

V

  1. Version control systems
  2. VI text editor
  3. Virtual machines

W

  1. WeblogUrls
  2. Wiki
  3. WikiBlogIntegration
  4. World of Warcraft
  5. wxWidgets

X

  1. XHTML
  2. XML
  3. XML to PHP translator
  4. XML-RPC
  5. XML-RPC Library for PHP (v 2.5)

Generated in about 0.054s.

(Used 4 db queries)