Property Naming

Once again I'm writing on naming conventions. This time I'm sure will be a short post to talk about conventions for publicly exposed properties. Like variables, functions, methods, classes, etc. property names need to be meaningful and informative to the programmer who is using the classes that you are writing. From the Framework Design Guideline book I found a great little excerpt by Krzysztof Cwalina which recommends that you worry about the tenses and readability of your properties when they are being used. Write a few lines of code that consumes your properties and see how they work. Take the readability differences the following code:

   14             //more readable

   15             if (objHashTable.Contains(strSomeValue))

   16             {

   17                 //do stuff

   18             }

   19 

   20             //less readable

   21             if (objHashTable.IsContained(strSomeValue))

   22             {

   23                 //do stuff

   24             }

CasingCasing options for your publicly exposed properties usually lead you to consider either PascalCasing or camelCasing. Which ever you choose, it is my belief that the casing of your methods and functions should be the same as the casing of your properties. If you use camelCasing (or PascalCasing) for one, use it for all publicly exposed items. The consistency will make the programmers using your classes much more comfortable. As you can see in the following image, the Hashtable object has a very nice, clean look to it's property, method and function list because of the consistent casing employed.



My Choice
Because I use PascalCasing on my functions and methods, I also use PascalCasing on properties to ensure consistency.

Posted By: Donald Belcham

Published at

Comments

Fear and Loathing
07/19/2006 08:27 AM by
Fear and Loathing

I’m really digging the series of blog posts over at Coding in an Igloo(an Emontonian) that cover

Coding in an Igloo
07/20/2006 12:05 AM by
Coding in an Igloo

While I was writing my last series (User Group Startup Stories) I noticed that the series idea helped...