Coding Standards

vishalneeraj-24503
Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 760
Today i am going to explain Coding standards:-
Following points need to be consider while doing code:-

1). Global variables or Class-level variables must always starts with m_ or _(underscore) i.e.
private string m_employee_name = string.empty.
private bool m_is_edit = false;
private int _employee_id = 0;


by defining global variables with m_/_ meaning any body can understand variables are defined as global.

2). Local variables or Function-level variables :- should be defined as simple as we define inside method such as
string employee_name = string.empty.
int employee_id = 0;

3). Private Method(s) :- First character of all words,except the first word are Upper Case and other characters are lower case.

For example:-
private string getValues(int id) //without underscore
{
}


//Or

 private string get_Values(int id)
{
}


4). Public Method(s) :- First character of all words will be in Upper Case and other characters will be in lower case.

For example:-
 public string GetValues(int id) //without underscore
{
}

//Or

 public string Get_Values(int id)
{
}


5). Constants :- These are defined with all characters in Upper case.
For exp:-
public const STATUS_ACTIVE = "AA";
public const STATUS_DEACTIVE = "DD";
public string EMPLOYEE_NAME = "EMP_NAME";

6). Proper Name(Variable/Controls) :- Always give proper name to variables to understand such as int emp_it = 0; or int
employee_id = 0;
controls name like TextBox id will start as
txt_employee_name
txt_employee_address
chk_employee_status -> Checkbox
ddl_employee_code -> Dropdownlist
gd_employee_details -> Gridview

and do same for all controls.

7). Class/Structure -> Give proper name such as

public class Employee_Master
public class Project_Master
public structure Position_Master

8). Properties :- Must be declared as First character will always be in capital case as shown below
    public string Employee_Name
{
get{return m_employee_name;}
set{m_employee_name = value;}
}

9). Enumeration :- Proper name as
Enum Priority
{
Low = 0,
Medium = 1,
High = 2
};


//Or
Enum Priority
{
Low,
Medium,
High
};

If we do not assign a value in enum, then enum by-default start with 0 index.

10). For Loop :- give proper or meaningful variables name in loop to understand as
for(int index = 0; index<=gd_employee_master.rows.count-1;index++)
{}

//Or
for(int counter = 0; counter <=gd_employee_master.rows.count-1;counter ++)
{}


By applying above approach, you can be a good coder

Thanks

Comments or Responses

Login to post response