Class Naming Conventions

I’m over half done my Naming Conventions series and I’m starting to notice that my posts are getting shorter and shorter. Again, this post will not be large, but there are a few important points I want to touch on as I discuss the naming of classes.

One of the very first things that I want to say is that, like any other variable, class names need to be meaningful. If the name of the class doesn’t properly represent the business/domain object it represents or the functionality it provides it will not be effective. From a developers perspective you also need to ensure that you make your classes easy to find. Don’t create a class and name it and it’s file two different things. I have seen this done and it is makes the code very difficult to work with. I know the VS IDE allows for this to happen, but most developers will look in the Solution Explorer for a file that has the exact same name as the class they are working with. If they’re working with a class that appears in intellisense as ‘Car’, they will overlook the class in Solution Explorer that is named ‘Automobile.cs’. In the end both of these recommendations serve two purposes: Readability and maintainability.

PascalCasing and camelCasing are both very viable options for naming classes. While preparing to write this post I was unable to come up with any discernable differences between the usage of either naming convention. The only thing that I could find was a recommendation by the Framework Design Guidelines book to use PascalCasing.

Hungarian Notation
At one time I worked on a project (back in my VB6 days) where all classes were prefixed with ‘cls’, all forms were prefixed with ‘frm’ and all modules were prefixed with ‘mod’. In the VS6 IDE you could easily tell each of those different items apart by the little icon that appeared next to them in the Solution Explorer. Today, using VS 2003/5, everything is a class. Imposing this convention in the VS 2003/5 environments would lead to absolutely everything being prefixed with ‘cls’. Once you have everything using the same prefix, the prefix no longer has any meaning or usefulness.

My Choice
I use PascalCasing when naming my classes. I’m not sure why I use it over camelCasing, but I do. In the end either would work, but only if you use your choice consistently.