Best Programming Practices - Naming Convention, Coding Standards
C# Coding Conventions (C# Programming Guide)
- Use pascal casing for Class/Type names, constants and method names.
- Use camel casing for local variable names and method parameters.
- Interface names should be prefix with "I" and follow pascal casing.
- Do not use Hungarian notation to name variables: - For example: string strEmployeeName, int nEmployeeAge, So to identify member variables follow camel casing as shown earlier.
- Use Meaningful, descriptive words to name variables.
- Do not use abbreviations or contractions as parts of identifier names. For example, use OnButtonClick rather than OnBtnClick.
- Name method names using verb-object pair, such as ShowEmployee().
- Do not use single character variable names, such as i , j, k etc. instead of that use Index or Counter for example:
for (int counter = 0; counter < count; counter ++)
{
……..
}
- Methods with return values should have a describing name the value it returns. E.g. GetEmployee().
- Suffix custom exception classes with Exception.
- Suffix custom attribute classes with Attribute.
- Prefix boolean variables with “is”. E.g. isEmployeeDeleted.
- While naming Namespace follow the standard : - <company name>.<product name>.<top level module>.<bottom level module> e.g. MyCompany.CMS.Web.Controls
- Avoid fully qualified namespace for Type. Good to use Using Statement.
- Using Statements should be sort by framework namespaces and then other namespaces.
- File name and class name should be same.
- Use pascal casing for file name. Keep related Class files in single Class Library.
- Declare local variable as close as possible for its first use.
- All Member variables should be declared at the top, with one line separating them from Properties and Methods.
- UI elements (Whether it is under Windows/Asp.Net) should use appropriate prefix so that you can identify them easily. Brief list given here:-
Control
|
Prefix
|
Label
|
lbl
|
TextBox
|
txt
|
DataGrid
|
dtg
|
Button
|
btn
|
ImageButton
|
imb
|
Hyperlink
|
hlk
|
DropDownList
|
ddl
|
ListBox
|
lst
|
DataList
|
dtl
|
Repeater
|
rep
|
Checkbox
|
chk
|
CheckBoxList
|
cbl
|
RadioButton
|
rdo
|
RadioButtonList
|
rbl
|
Image
|
img
|
Panel
|
pnl
|
PlaceHolder
|
phd
|
Table
|
tbl
|
Validators
|
val
|
Get in touch for more information. Happy Coding .. :-)
Best Programming Practices - Naming Convention, Coding Standards
Reviewed by Ravi Kumar
on
4:57 PM
Rating:

No comments: