Monday, June 6, 2011

Coding Convention

Have you ever tried maintaining an existing code where you can't understand what its variables meant? I have and let me tell you... it's not funny at all!

Although not following any coding convention doesn't cause your program not to work, it is advised you follow one. It makes it easier for other developers to read and understand your code which makes it easier to maintain. It also helps you when you maintain you own code specially when you developed it more than a year ago.

In C#, it is advised to use Pascal casing for names. Pascal casing means that the first letter of every word be capitalized. Some examples of this are RetrieveEmployeeInfo and ComputeMonthlySalary. Based on what I've read, this is used for constant variables (I'm used to having all my constants in uppercase. I guess it's time to change that.) and for public and protected method names. When declaring variables and passing parameters, Camel casing is used. Camel casing is similar to Pascal casing. The only difference is that in Camel casing, the first letter of the first word of a variable is in lowercase. Some examples of this are employeeInfo and monthlySalary. When declaring a member variable, Camel casing is used with an underscore before the first word. An example of this is _employeeInfo.

No comments:

Post a Comment