Monday, 25 August 2014

Writing clean code in c#



Use the following three conventions for capitalizing identifiers.
Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example:
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:
backColor
Uppercase
All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters. For example:

System.IO
System.Web.UI


Now how our code should be using above three capitalizing identifires as Microsoft Standerds
(Reference :  http://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx)




  1. Refer the above capitalizing styles 
  2. Give summery to your code / Method / Class
     Now check below code as example.





I found following correction in the code. So that code will look fine
Corrections :
 

Ø   Class Level private vairable always preceeded with "_"
Ø   Class Should have Summery
Ø   Method Should have Summery
Ø   All the properties Should be in one regions
Ø   All the public methods should be in one regions
Ø   Class Name Should be in


Now corrected code should be look like this.








      
3:
Use && and || when you only care about the result and want to know that result as soon as possible and none of your expressions have side effects that must occur even if the boolean condition is not met. That is to say, pretty much always.
Use & and | when every expression must be evaluated (for example, if you have side effects from your expressions). But since you should never have side effects that your program depends on that must occur even if the boolean condition is not met, you should probably not be using & and |.
For example, this would probably be exceptionally silly:
if (false & somethingThatUpdatesTheDatabase()) { /* ... */ }






  4: Use:? Operator rather than below statement

Can be written as 





5:Use Var Vaiable wherever is possible

     can be wrriten as





6: Remove un used usings from your file.
    Refer this link :
http://ajayrgandhi.blogspot.in/2014/08/how-to-remove-un-used-usings-in-visual.html

No comments:

Post a Comment