Posted by: terryhowe | September 27, 2009

Clean Code: Names

I am currently reading Clean Code by Robert C. Martin and I am going to summarize a couple chapters.  The best reason to write about anything is to learn it.  So far, the book has not been anything new, but I’d like to be able to discuss this topic with more structure.

The first topic Martin discusses is names and names are probably one thing I obsess over more than most programmers.  Martins points are:

  • Use revealing names: Avoid using short names like x or i unless the scope of the variable is very small.
  • Avoid disinformation: Avoid words with other confusing meanings
  • Make meaningful names
  • Make them pronouncable
  • Make them searchable: Martin doesn’t mention this, but I hate using i for a variable name because it is difficult to search for and hard to see.
  • Don’t use member prefixes: Generally, I agree with this.  No need for special prefixes for member variables, but some standards can be nice like using “the” for singletons.
  • Don’t use hungarian notation
  • Class names should be nouns
  • Method names should be verbs or verb phrases

One thing he doesn’t mention that I like to do is avoid abbreviations.  It makes it harder to remember if you used indx or idx for index.  Just use index.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: