Coding standard for vb.net and C#


Hi
Just before few months i was working for one big MNC client. There we were implementing some coding standard for vb.net and C# project. I have summarized that coding standard like this

Coding standard for vb.net

1. Declaration of variable should be in Camel case

2. Private Name should be in Camel case

3. Public and Properties should be in Pascal case

4. All Constant should be in Caps or Upper Case

5. “_” should not be used

6. Object should not be used

7. Short should not used

8. CShort should not be used

9. Method name should be in Pascal case

10. Parameter variable should be in Camel case

11. Exit sub and exit should be removed

12. Call keyword should be removed

13. Function Name should not be used as return variable

14. I,k,j should not be used. We should have to used proper naming

15. “ ” should be replaced with string.empty

16. Option strict and Option Explicit should be ON

17. Index1 should be “indexOne”

18. Function name should not be with “fun” prefix. It should be in pascal

19. Subroutine name should not be with “sub” prefix and it should be in pascal

20. “On Error Resume Next” statement is there then no need to use try catch block.

Coding Standard for C#

1. Declaration of variable should be in Camel case
string empName=string.Empty;

2. Class Name should be in Pascal

public class HelloWorld()
{
}

3. Method name should be Pascal

public string SayHello( String name )
{
return name;
}

4. All Constant should be in Caps or Upper Case

5. “_” should not be used while giving parameter and variable Name

string emp_Name;

It should be like this
string empName;

6. Parameter variable should be in Camel case

public string SayHello( String name )
{
return name;
}

7. “ ” should be replace by string.empty

8. I,j,k Naming should not be used.

9. Comment should not be written in every line of code. We should have to write proper method name to make more readable code and give the comment where logic is some complex.

10. use C# specified Type rather than alias type defined in the System namespace.

Good

int age;
string name;

Not Good

Int16 age;
String name;

11. Try to minimize the exception in code. Use specific exception handling for particular type of error

12 . Try to use list instead of “Array” or “Arraylist”.

13. use using keyword to dispose idisposable object while working with “Sqlconnection”,sqlcommand etc.

14. Use proper exception handling code while writing the code .

15. If some method, we are using in one class only then we should not have to use Public access modifier.

Note: If you feel, this is not a proper or i m missing some important point then feel free to share your idea.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: