01 June 2011

.net Naming Conventions (Part 1)

What is .net Programming Standard for Naming Convention?
There are a number of Naming Convention that programmers used this days and this has always been a controversial topic if which one of this Naming Convention is the standard one. There have been a lot of arguments regarding the use of Hungarian Notation of Naming Convention and the combination of Pascal Casing and Camel Casing as the Programming Standard for Naming Convention (Too bad I can't enumerate them all here!). To cut down all the ideas, it's really up to the preferences of the team who will be building the program which Naming Convention they will be using to promote readability and integrity of their codes

All the Programming Naming Conventions that you will see here are all my personal preferences. I will only include those types that I used the most so that I can provide enough reasons why I preferred this conventions. I'm just a class newbie so don't expect much of a techie explanation from me.


Classes
I put the prefix "cls" after a noun when naming my classes. This can help me identify the classes from the other items in my solution. It also helps a lot in intellisense grouping. You only have to type "cls" then after that you will have the list of all the classes that you made in your solution. Try to avoid abbreviations, and try to always use nouns. Always use a capital letter on the first letter of each words. If you want to create a class calculator then use "clsCalculator" and not "clsMyCalculator". When you want to add an adjective to the name of your class, I prefer putting the adjective between the prefix and then the noun. Use "clsScientificCalculator".

Public Class clsCalculator
Public Class clsSettings
Public Class clsAdminSettings

Subs and Functions
I prefer Pascal Casing for my subs and functions. No underscores except for the event handlers. Avoid abbreviation and stop being too lazy. Try to promote readability on your codes. Be descriptive on the names of your subs and functions and use verbs to describe what it will do.

Sub DoSomething()
Sub CalculateAverage()

Class-level Private and Protected variables
For this variables I just put an underscore before it's name in Camel Case. I find this very useful because of it's uniqueness and you can easily individualize those private variables from the other variables in your class.

Private _studentID As Integer
Private _productCode As String

Properties and Public Member Variables
Pascal Case, No underscores and abbreviations. This convention is consistent with the .NET Framework and is easy to read.

Public Property Gender As Boolean
Public Property Age As Date

Parameters
Parameter can either be an input type or an output type. For input type I put the prefix "pi" which stands for parameter input and use the prefix "po" which stands for parameter output. Most programmer use Camel Case for naming their parameters. But I put prefixes on my parameter's to know that it is a parameter type variable and also to avoid the possible misapply of the said variable.

Byval piLastname As String
Byref poAverage As Double

Procedure-level variables
Camel Case. It's easy to read and this variable does not really need that much particularity since it will only be used inside it's procedure.

Dim ageLimit As Integer
Dim contractSalary As Double

As you can see I don't really follow just one single Naming Convention. I used different conventions on different types depending on the situation so that my codes will be as readable and integrated as possible. On my next blog I will be sharing with you the naming conventions that I used for my controls and other items that you can add in your windows solution explorer.

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More