Difference between revisions of "Coding guideline - Common rules"

From Catglobe Wiki
Jump to: navigation, search
m (Added missing s and fixed some minor typos)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Introduction==  
+
<accesscontrol>Main:MyGroup</accesscontrol>
This document aims at giving common rules that
+
== Introduction ==
developers MUST follow to ensure not only consistency in the whole
 
application but also the ease of code reading and maintaining. Due to
 
the fact that we are working mainly on C# language, all examples will
 
be given in this language only.
 
  
Please refer to the .NET Framework Design
+
This document aims at giving common rules that developers MUST follow to ensure not only consistency in the whole application but also the ease of code reading and maintaining. Due to the fact that we are working mainly on C# language, all examples will be given in this language only.  
Guidelines (http://msdn.microsoft.com/en-us/library/czefa0ke.aspx)
 
for a complete set of guidelines suggested by Microsoft.
 
  
==Terms and Conventions==
+
Please refer to the .NET Framework Design Guidelines (http://msdn.microsoft.com/en-us/library/czefa0ke.aspx) for a complete set of guidelines suggested by Microsoft.  
===Naming Terms===
 
There are 3 terms used for naming files, class
 
names, variable names, etc. All are listed in this section.
 
  
'''Pascal case'''
+
== Terms and Conventions ==
  
The first letter in the identifier and the first
+
=== Naming Terms ===
letter of each subsequent concatenated word are capitalized. You can
 
use Pascal case for identifiers of three or more characters.
 
  
For example:
+
There are 3 terms used for naming files, class names, variable names, etc. All are listed in this section.
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
<FONT COLOR="#2b91af">CatGlobeImageButton</FONT>,
 
<FONT COLOR="#2b91af">LanguageEditor</FONT>
 
</FONT>
 
  
'''Camel case'''
+
'''Pascal case'''  
  
The first letter of an identifier is lowercase and
+
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.  
the first letter of each subsequent concatenated word is capitalized.
 
  
For example:  
+
For example: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">CatGlobeImageButton</font>, <font color="#2b91af">LanguageEditor</font> </font>  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
<FONT COLOR="#2b91af">resourceId</FONT>,
 
<FONT COLOR="#2b91af">resourceTemplateId</FONT>
 
</FONT>
 
  
'''Uppercase'''
+
'''Camel case'''  
All letters in the identifier are capitalized. Use
 
this convention only for identifiers that consist of two or fewer
 
letters.
 
  
For example:
+
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
<FONT COLOR="#2b91af">ID</FONT>,
 
<FONT COLOR="#2b91af">UI</FONT>,
 
<FONT COLOR="#2b91af">IO</FONT>
 
</FONT>
 
  
==Style Guidelines==
+
For example: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">resourceId</font>, <font color="#2b91af">resourceTemplateId</font> </font>
===File Organization===
 
'''Location '''
 
  
* Class file should be put in directory whose path follows class's namespace. This makes finding a class easier.
+
'''Uppercase''' All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters.  
  
For example: code file of class
+
For example: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">ID</font>, <font color="#2b91af">UI</font>, <font color="#2b91af">IO</font> </font>  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#2b91af" >''CatGlobe.Web.UI.WebControls.CatGlobeImageButton''</FONT>
 
should be found in side <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">&ldquo;''{CODE_BASE}\CatGlobe\Web\UI\WebControls''&rdquo;</FONT>
 
  
'''Naming  '''
+
== Style Guidelines ==
  
* Always use ''Pascal'' for naming code file.
+
=== File Organization ===
* Source files should be given the name of the first public class in the file plus &ldquo;.cs&rdquo;. The purpose of this naming is clear, it increases the consistent of organization and also the maintainability.
 
  
For example: code file
+
'''Location '''  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">&ldquo;''{CODE_BASE}\CatGlobe\Web\UI\WebControls\CatGlobeImageButton.cs''&rdquo;</FONT>
 
should have the first public class as <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#2b91af">''CatGlobeImageButton''</FONT>
 
  
'''Content'''
+
*Class file should be put in directory whose path follows class's namespace. This makes finding a class easier.
* There should be only one <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">namespace</FONT> declaration in one code file only.
 
* One source file should contain only one public class/interface/enum, although multiple internal classes are allowed. Delegates and Interfaces are allowed to be put in the same file as class/interface/enum.
 
  
''<U>Should</U>''
+
For example: code file of class <font face="Courier New, monospace" size="2" color="#2b91af" style="font-size: 9pt;">''CatGlobe.Web.UI.WebControls.CatGlobeImageButton''</font> should be found in side <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">“''{CODE_BASE}\CatGlobe\Web\UI\WebControls''”</font>  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">sealed </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">CatTask</FONT> &#58; <FONT COLOR="#2b91af">PersistentObject</FONT>, <FONT COLOR="#2b91af">ICatTaskClientObject</FONT>, <FONT COLOR="#2b91af">IComparable</FONT>
 
:{
 
::<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">sealed </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">CatTasksAccess</FONT> &#58; <FONT COLOR="#2b91af">AccessBase</FONT>
 
::{
 
::}  
 
:}
 
</FONT>
 
  
''<U>Should not</U>''
+
'''Naming '''  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">sealed </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">CatTask</FONT> &#58; <FONT COLOR="#2b91af">PersistentObject</FONT>, <FONT COLOR="#2b91af">ICatTaskClientObject</FONT>, <FONT COLOR="#2b91af">IComparable</FONT>
 
:{
 
:}
 
  
:[<FONT COLOR="#2b91af">Serializable</FONT>]
+
*Always use ''Pascal'' for naming code file.
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">sealed </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">StringConstant</FONT>
+
*Source files should be given the name of the first public class in the file plus “.cs”. The purpose of this naming is clear, it increases the consistent of organization and also the maintainability.
:{
 
:}
 
</FONT>
 
  
* Classes member should be grouped into sections (Fields, Constructors, Properties, Events, Methods, Private interface implementations, Nested types). And there should be a region name in <FONT COLOR="#0047ff">''#endregion ''</FONT> instructive although it is not required. Regions can be shown/hide while viewing with VS thus increasing the readability.
+
For example: code file <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">“''{CODE_BASE}\CatGlobe\Web\UI\WebControls\CatGlobeImageButton.cs''”</font> should have the first public class as <font face="Courier New, monospace" size="2" color="#2b91af" style="font-size: 9pt;">''CatGlobeImageButton''</font>  
  
For example:
+
'''Content'''
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">sealed </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">CatTask</FONT> &#58; <FONT COLOR="#2b91af">PersistentObject</FONT>, <FONT COLOR="#2b91af">ICatTaskClientObject</FONT>, <FONT COLOR="#2b91af">IComparable</FONT>
 
:{
 
::<FONT COLOR="#0000ff">#region </FONT>AccessClass
 
  
::<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">sealed </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">CatTasksAccess</FONT> &#58; <FONT COLOR="#2b91af">AccessBase</FONT>  
+
*There should be only one <font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">namespace</font> declaration in one code file only.
::{
+
*One source file should contain only one public class/interface/enum, although multiple internal classes are allowed. Delegates and Interfaces are allowed to be put in the same file as class/interface/enum.
::}
 
  
::<FONT COLOR="#0000ff">#endregion  </FONT>AccessClass
+
''<u>Should</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
::<FONT COLOR="#0000ff">#region </FONT>Private Instance Fields
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">sealed </font><font color="#0000ff">class </font><font color="#2b91af">CatTask</font> : <font color="#2b91af">PersistentObject</font>, <font color="#2b91af">ICatTaskClientObject</font>, <font color="#2b91af">IComparable</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">sealed </font><font color="#0000ff">class </font><font color="#2b91af">CatTasksAccess</font> : <font color="#2b91af">AccessBase</font></font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Should not</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">sealed </font><font color="#0000ff">class </font><font color="#2b91af">CatTask</font> : <font color="#2b91af">PersistentObject</font>, <font color="#2b91af">ICatTaskClientObject</font>, <font color="#2b91af">IComparable</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">[<font color="#2b91af">Serializable</font>]</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">sealed </font><font color="#0000ff">class </font><font color="#2b91af">StringConstant</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Classes member should be grouped into sections (Fields, Constructors, Properties, Events, Methods, Private interface implementations, Nested types). And there should be a region name in <font color="#0047ff">''#endregion''</font> instructive although it is not required. Regions can be shown/hide while viewing with VS thus increasing the readability.
 +
 
 +
For example: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
::<FONT COLOR="#0000ff">private  int</FONT> resourceId;
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">sealed </font><font color="#0000ff">class </font><font color="#2b91af">CatTask</font> : <font color="#2b91af">PersistentObject</font>, <font color="#2b91af">ICatTaskClientObject</font>, <font color="#2b91af">IComparable</font></font>
::<FONT COLOR="#0000ff">private  int</FONT> resourceTemplateId;
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>AccessClass</font>
  
::<FONT COLOR="#0000ff">#endregion </FONT>Private Instance Fields
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">sealed </font><font color="#0000ff">class </font><font color="#2b91af">CatTasksAccess</font> : <font color="#2b91af">AccessBase</font></font>
:}
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
''<U>A propose class file with regions:</U>''
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>AccessClass</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">SampleClass</FONT>
 
:{
 
::<FONT COLOR="#0000ff">#region </FONT>Nested Enums, Structs, and Classes
 
::<FONT COLOR="#0000ff">#endregion </FONT>Nested Enums, Structs, and Classes
 
  
::<FONT COLOR="#0000ff">#region </FONT>Constructors &amp; Finalizers
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Private Instance Fields</font>
::<FONT COLOR="#0000ff">#endregion </FONT>Constructors &amp; Finalizers
 
  
::<FONT COLOR="#0000ff">#region </FONT>Member variables
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private int</font> resourceId;</font>
::<FONT COLOR="#0000ff">#endregion </FONT>Member variables
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private int</font> resourceTemplateId;</font>
  
::<FONT COLOR="#0000ff">#region </FONT>roperties
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Private Instance Fields</font>  
::<FONT COLOR="#0000ff">#endregion </FONT>Properties
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
::<FONT COLOR="#0000ff">#region </FONT>Methods
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
::<FONT COLOR="#0000ff"> #endregion </FONT>Methods
 
:}
 
</FONT>
 
  
* There should not be more than ''<U>500 lines of code</U>'' inside one file. Files containing more than 500 lines have less readability than the ones with less than 500 lines. There is one exception that we should not take into account on this rules, that are auto-generated files since most of the time we do not maintain these files directly.
+
''<u>A propose class file with regions:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
* Each line of code ''<U>should not exceed 120 characters</U>''. Lines with more than 120 characters normally require code viewer using the horizontal scrollbar thus decrease readability.
 
  
===Tabs, Indenting, Spacing and Bracing===
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>
'''Tabs and Indenting'''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Nested Enums, Structs, and Classes</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Nested Enums, Structs, and Classes</font>
  
*Tab characters (\0x09) '''MUST NOT''' be used in code. All tabs must be replaced by 3 space characters.
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Constructors &amp; Finalizers</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Constructors &amp; Finalizers</font>
 +
 
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Member variables</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Member variables</font>
 +
 
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>roperties</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Properties</font>
 +
 
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Methods</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Methods</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*There should not be more than ''<u>500 lines of code</u>'' inside one file. Files containing more than 500 lines have less readability than the ones with less than 500 lines. There is one exception that we should not take into account on this rules, that are auto-generated files since most of the time we do not maintain these files directly.
 +
*Each line of code ''<u>should not exceed 120 characters</u>''. Lines with more than 120 characters normally require code viewer using the horizontal scrollbar thus decrease readability.
 +
 
 +
=== Tabs, Indenting, Spacing and Bracing ===
 +
 
 +
'''Tabs and Indenting'''
 +
 
 +
*Tab characters (\0x09) '''MUST NOT''' be used in code. All tabs must be replaced by 3 space characters.  
 
*All indentation '''MUST''' be done with '''''3 space characters'''''.
 
*All indentation '''MUST''' be done with '''''3 space characters'''''.
  
'''Spacing'''
+
'''Spacing''' Spaces improve readability by decreasing code density. Here are some guidelines for the use of space characters within code:  
Spaces improve readability by decreasing code density. Here are some guidelines for the use of space characters within code:
 
  
 
*'''Do''' use a single space after a comma between function arguments.
 
*'''Do''' use a single space after a comma between function arguments.
:Right:<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">Console.In.Read(myChar,0,1);</FONT>
 
:Wrong: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">Console.In.Read(myChar,0,1);</FONT>
 
  
*'''Do not''' use a space after the parenthesis and function arguments.  
+
:Right:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">Console.In.Read(myChar,0,1);</font>
:Right: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">CreateFoo(myChar, 0, 1);</FONT>
+
:Wrong: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">Console.In.Read(myChar,0,1);</font>
:Wrong: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">CreateFoo(<SPAN STYLE="background: #ff0000"> </SPAN>myChar, 0, 1<SPAN STYLE="background: #ff0000"> </SPAN>)</FONT>
+
 
+
*'''Do not''' use a space after the parenthesis and function arguments.
*'''Do not''''' use spaces between a function name and parenthesis.
+
 
:Right: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">CreateFoo(); </FONT>
+
:Right: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">CreateFoo(myChar, 0, 1);</font>  
:Wrong: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">CreateFoo<SPAN STYLE="background: #ff0000"> </SPAN>()</FONT>
+
:Wrong: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">CreateFoo(<span style="background: rgb(255, 0, 0) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>myChar, 0, 1<span style="background: rgb(255, 0, 0) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>)</font>
+
 
*'''Do not''''' use spaces inside brackets.
+
*'''Do not'''''use spaces between a function name and parenthesis.''
:Right: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">x = dataArray[index];</FONT>
+
 
:Wrong: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">x = dataArray[<SPAN STYLE="background: #ff0000"> </SPAN>index<SPAN STYLE="background: #ff0000"> </SPAN>]; </FONT>
+
:Right: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">CreateFoo(); </font>  
+
:Wrong: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">CreateFoo<span style="background: rgb(255, 0, 0) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>()</font>
 +
 
 +
*'''Do not'''''use spaces inside brackets.''
 +
 
 +
:Right: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">x = dataArray[index];</font>  
 +
:Wrong: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">x = dataArray[<span style="background: rgb(255, 0, 0) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>index<span style="background: rgb(255, 0, 0) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>]; </font>
 +
 
 
*'''Do''' use a single space before flow control statements.
 
*'''Do''' use a single space before flow control statements.
:Right: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">while<SPAN STYLE="background: #c0c0c0"> </SPAN>(x == y)</FONT>
+
 
:Wrong: <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">while(x==y)</FONT>
+
:Right: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">while<span style="background: rgb(192, 192, 192) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>(x == y)</font>  
+
:Wrong: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">while(x==y)</font>
 +
 
 
*'''Do''' use a single space before and after comparison operators.
 
*'''Do''' use a single space before and after comparison operators.
:Right:  <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">if (x<SPAN STYLE="background: #c0c0c0"> </SPAN>==<SPAN STYLE="background: #c0c0c0"> </SPAN>y)</FONT>
 
:Wrong:  <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">if (x==y)</FONT>
 
  
'''Bracing'''
+
:Right: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">if (x<span style="background: rgb(192, 192, 192) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>==<span style="background: rgb(192, 192, 192) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"> </span>y)</font>
 +
:Wrong: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">if (x==y)</font>
  
* Open braces must always be at the beginning of the line after the statement that begins the block. This increases readability of code.
+
'''Bracing'''  
''<U>Must:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">if </FONT>((CatTaskStatus.Status == CatTaskCommon.<FONT COLOR="#2b91af">CatTaskStatus</FONT>.Failed)
 
:{
 
::<FONT COLOR="#2b91af">CatTaskCompleted</FONT> ctc = <FONT COLOR="#2b91af">CatTaskCompleted</FONT>.GetByLatestCompletedDate(<FONT COLOR="#0000ff">this</FONT>);
 
::<FONT COLOR="#0000ff">if </FONT> (ctc != <FONT COLOR="#0000ff">null</FONT>)
 
:::completedDate = ctc.CompletedDate;
 
::<FONT COLOR="#0000ff">return </FONT>completedDate;
 
:}
 
:<FONT COLOR="#0000ff">else</FONT>
 
:{
 
::...
 
:}
 
</FONT>
 
  
''<U>Must not:</U>''
+
*Open braces must always be at the beginning of the line after the statement that begins the block. This increases readability of code.
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">if </FONT>((CatTaskStatus.Status == CatTaskCommon.<FONT COLOR="#2b91af">CatTaskStatus</FONT>.Failed) <FONT COLOR="#ff0000">'''{'''</FONT>''' '''<FONT COLOR="#ff0000"><FONT FACE="Arial, sans-serif">'''=&gt; Wrong brace's location'''</FONT></FONT>
 
::<FONT COLOR="#2b91af">CatTaskCompleted</FONT> ctc = <FONT COLOR="#2b91af">CatTaskCompleted</FONT>.GetByLatestCompletedDate(<FONT COLOR="#0000ff">this</FONT>);
 
::<FONT COLOR="#0000ff">if </FONT>(ctc != <FONT COLOR="#0000ff">null</FONT>) <FONT COLOR="#ff0000">'''{ '''</FONT>
 
:::completedDate = ctc.CompletedDate;
 
::}
 
::<FONT COLOR="#0000ff">return </FONT> completedDate;
 
:}
 
</FONT>
 
  
* For anonymous methods and lambda expressions, the braces must be indent at the same level with its declaration.
+
''<u>Must:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">private </FONT> SampleDelegate _mySampleDelegate = <FONT COLOR="#0000ff">delegate</FONT>()             
 
::::::::&nbsp;&nbsp;&nbsp;'''{'''
 
::::::::&nbsp;&nbsp;&nbsp;'''};'''
 
  
:<FONT COLOR="#0000ff">private </FONT> SampleDelegate _mySampleDelegate = (name) =&gt;
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>((CatTaskStatus.Status == CatTaskCommon.<font color="#2b91af">CatTaskStatus</font>.Failed)</font>
::::::::&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'''{'''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
::::::::&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'''}''';
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">CatTaskCompleted</font> ctc = <font color="#2b91af">CatTaskCompleted</font>.GetByLatestCompletedDate(<font color="#0000ff">this</font>);</font>
</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font> (ctc&nbsp;!= <font color="#0000ff">null</font>) </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">completedDate = ctc.CompletedDate;</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">return </font>completedDate;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">else</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">...</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>((CatTaskStatus.Status == CatTaskCommon.<font color="#2b91af">CatTaskStatus</font>.Failed) <font color="#ff0000">'''{'''</font><font color="#ff0000"><font face="Arial, sans-serif">'''=&gt; Wrong brace's location'''</font></font> </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">CatTaskCompleted</font> ctc = <font color="#2b91af">CatTaskCompleted</font>.GetByLatestCompletedDate(<font color="#0000ff">this</font>);</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(ctc&nbsp;!= <font color="#0000ff">null</font>) <font color="#ff0000">'''{'''</font> </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">completedDate = ctc.CompletedDate;</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">return </font> completedDate;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*For anonymous methods and lambda expressions, the braces must be indent at the same level with its declaration.
 +
 
 +
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font> SampleDelegate _mySampleDelegate = <font color="#0000ff">delegate</font>() </font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">&nbsp;&nbsp;&nbsp;'''{'''</font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">&nbsp;&nbsp;&nbsp;'''};'''</font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font> SampleDelegate _mySampleDelegate = (name) =&gt; </font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">&nbsp;&nbsp;&nbsp;'''{'''</font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">&nbsp;&nbsp;&nbsp;'''}''';</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
 
*Must not put block that contains more than 2 statements in the same line:
 
*Must not put block that contains more than 2 statements in the same line:
''<U>Must not</U>'':
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">if </FONT> (ctc != <FONT COLOR="#0000ff">null</FONT>) {<FONT COLOR="#0000ff"></FONT>completedDate = ctc.CompletedDate; <FONT COLOR="#0000ff">return</FONT> completedDate; }
 
</FONT>
 
  
*With single statement blocks, using of braces is optionnal. It is encourage to not use the braces to save number of line of code.  
+
''<u>Must not</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Should:</U>''
+
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font> (ctc&nbsp;!= <font color="#0000ff">null</font>) {<font color="#0000ff"></font>completedDate = ctc.CompletedDate; <font color="#0000ff">return</font> completedDate; }</font>
:<FONT COLOR="#0000ff">if </FONT> (ctc != <FONT COLOR="#0000ff">null</FONT>)
+
 
::completedDate = ctc.CompletedDate;  
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
</FONT>
+
 
 +
*With single statement blocks, using of braces is optionnal. It is encourage to not use the braces to save number of line of code.
 +
 
 +
''<u>Should:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font> (ctc&nbsp;!= <font color="#0000ff">null</font>) </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">completedDate = ctc.CompletedDate;</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
''<U>Should not:</U>''
+
''<u>Should not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
 
:<FONT COLOR="#0000ff">if </FONT> (ctc != <FONT COLOR="#0000ff">null</FONT>)
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font> (ctc&nbsp;!= <font color="#0000ff">null</font>)</font>
:<FONT COLOR="#c5000b">{</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#c5000b">{</font> </font>
::<FONT COLOR="#c5000b">completedDate = ctc.CompletedDate;</FONT> <FONT COLOR="#ff0000"><FONT FACE="Arial, sans-serif">'''=&gt; 3 lines of code do the same as 1 line'''</FONT></FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#c5000b">completedDate = ctc.CompletedDate;</font> <font color="#ff0000"><font face="Arial, sans-serif">'''=&gt; 3 lines of code do the same as 1 line'''</font></font></font>  
:<FONT COLOR="#c5000b">}</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#c5000b">}</font></font>
</FONT>
+
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
 
*There are exceptions that brace should be placed on the same line as the keyword that requires braces.
 
*There are exceptions that brace should be placed on the same line as the keyword that requires braces.
''<U>One statement code block:</U>''
 
  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
''<u>One statement code block:</u>''  
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">int </FONT> CompletedMailTemplateId
 
:{
 
::<FONT COLOR="#0000ff">get</FONT> { <FONT COLOR="#0000ff">return </FONT> completedMailTemplateId; } <FONT COLOR="#ff0000"><FONT FACE="Arial, sans-serif">'''=&gt; It is much nicer than having 4 lines of code'''</FONT></FONT>
 
::<FONT COLOR="#0000ff">set</FONT> { completedMailTemplateId = <FONT COLOR="#0000ff">value</FONT>; }
 
:}
 
</FONT>
 
  
''<U>.NET 3.0 property syntax:</U>''
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">int </FONT>MyProperty { <FONT COLOR="#0000ff">get</FONT>; <FONT COLOR="#0000ff">set</FONT>; }
 
</FONT>
 
  
<DIV style="background: #c0c0c0; border: #000000 solid 1pt; padding: 5px; color: #0000ff">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">int </font> CompletedMailTemplateId</font>
'''Tips:'''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
<BR />
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">get</font> { <font color="#0000ff">return </font> completedMailTemplateId; } <font color="#ff0000"><font face="Arial, sans-serif">'''=&gt; It is much nicer than having 4 lines of code'''</font></font></font>
All
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">set</font> { completedMailTemplateId = <font color="#0000ff">value</font>; }</font>  
rules in this section can be applied automatically by applying a
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
common ''Visual Studio settings file''. Developers just have to
 
remember to apply these rules by pressing ''Ctrl + K + D''
 
(under default installation) or ''Ctrl + E + C ''using
 
Resharper before committing.
 
</DIV>
 
  
=== Commenting ===
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>.NET 3.0 property syntax:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">int </font>MyProperty { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
<div style="border: 1pt solid rgb(0, 0, 0); padding: 5px; background: rgb(192, 192, 192) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 255);">
 +
'''Tips:''' <br> All rules in this section can be applied automatically by applying a common ''Visual Studio settings file''. Developers just have to remember to apply these rules by pressing ''Ctrl + K + D'' (under default installation) or ''Ctrl + E + C ''using Resharper before committing.
 +
</div>
 +
=== Commenting ===
  
 
Comments should be used to describe intention, algorithmic overview, and/or logical flow. It would be ideal, if from reading the comments alone, someone other than the author could understand a function’s intended behavior and general operation. While there are no minimum comment requirements and certainly some very small routines need no commenting at all, it is hoped that most routines will have comments reflecting the programmer’s intent and approach.  
 
Comments should be used to describe intention, algorithmic overview, and/or logical flow. It would be ideal, if from reading the comments alone, someone other than the author could understand a function’s intended behavior and general operation. While there are no minimum comment requirements and certainly some very small routines need no commenting at all, it is hoped that most routines will have comments reflecting the programmer’s intent and approach.  
Line 271: Line 263:
 
*Do not decorate your comment with special charaters.
 
*Do not decorate your comment with special charaters.
  
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;"></font>
+
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;"></font>  
  
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// *********************************</font>
+
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// *********************************</font>  
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// Comments block</font>
+
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// Comments block</font>  
 
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// **********************************</font>
 
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// **********************************</font>
  
Line 281: Line 273:
 
*Avoid comments that explain the obvious. Code should be self-explanatory. Good code with readable variable and method names should not require comments.
 
*Avoid comments that explain the obvious. Code should be self-explanatory. Good code with readable variable and method names should not require comments.
  
''<u>Should not</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
+
''<u>Should not</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">Resource Id </font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">Resource Id</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>  
 
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">int </font>resourceId;</font>
 
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">int </font>resourceId;</font>
  
Line 294: Line 286:
 
*Include Task-List keywords flags to enable comment-filtering. These comment can be tracked by using Visual Studio Task List window or just simply by searching.
 
*Include Task-List keywords flags to enable comment-filtering. These comment can be tracked by using Visual Studio Task List window or just simply by searching.
  
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;"></font>
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;"></font>  
  
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// TODO: Fix this</font>
+
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// TODO: Fix this</font>  
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// HACK: work-around temporarily while waiting for better solution</font>
+
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// HACK: work-around temporarily while waiting for better solution</font>  
 
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// UNDONE: Will be done in version xxxx</font>
 
:<font face="Courier New, monospace" size="2" color="#008000" style="font-size: 9pt;">// UNDONE: Will be done in version xxxx</font>
  
Line 312: Line 304:
 
*Use comment tags whenever possible, this could give very much help on generating help files. The most used tags are: <font color="#33cc66"><font face="Courier New, monospace">&lt;summary&gt;, &lt;param&gt;, &lt;paramref&gt;, &lt;return&gt;, &lt;exception&gt;, &lt;see&gt;, &lt;seeAlso&gt;</font></font>.
 
*Use comment tags whenever possible, this could give very much help on generating help files. The most used tags are: <font color="#33cc66"><font face="Courier New, monospace">&lt;summary&gt;, &lt;param&gt;, &lt;paramref&gt;, &lt;return&gt;, &lt;exception&gt;, &lt;see&gt;, &lt;seeAlso&gt;</font></font>.
  
''<u>Class comment:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
+
''<u>Class comment:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">This is my sample class for illustating comment on coding guide line document</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">This is my sample class for illustating comment on coding guide line document</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>  
 
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
 
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
 
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
''<u>Method comment:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
+
''<u>Method comment:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">This is my test method. </font><font color="#008000">It is created for demonstrating how to write comment for </font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">This is my test method. </font><font color="#008000">It is created for demonstrating how to write comment for</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">a method.</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">a method.</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;param name="arg1"&gt;</font><font color="#008000">This is sample argument 1. It will be used for ... </font><font color="#808080">&lt;/param&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;param name="arg1"&gt;</font><font color="#008000">This is sample argument 1. It will be used for ... </font><font color="#808080">&lt;/param&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;param name="arg2"&gt;</font><font color="#008000">This is sample argument 2. It will be used for ...</font><font color="#808080">&lt;/param&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;param name="arg2"&gt;</font><font color="#008000">This is sample argument 2. It will be used for ...</font><font color="#808080">&lt;/param&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;returns&gt;</font><font color="#008000">Return the result string.</font><font color="#808080">&lt;/returns&gt;</font></font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;returns&gt;</font><font color="#008000">Return the result string.</font><font color="#808080">&lt;/returns&gt;</font></font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">protected </font><font color="#0000ff">string </font> MyMethod(<font color="#0000ff">string </font> arg1, <font color="#0000ff">string </font> arg2)</font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">protected </font><font color="#0000ff">string </font> MyMethod(<font color="#0000ff">string </font> arg1, <font color="#0000ff">string </font> arg2)</font>  
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>  
 
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
Line 343: Line 335:
  
 
A detail explaination of all comment tags can be found here: http://thoughtpad.net/alan-dean/cs-xml-documentation.  
 
A detail explaination of all comment tags can be found here: http://thoughtpad.net/alan-dean/cs-xml-documentation.  
</div>
+
</div>
 +
=== Naming ===
 +
 
 +
==== Common rules ====
 +
 
 +
*Always use Camel Case or Pascal Case for naming. With private instance member, prefix variable name with an underscore '_'.
 +
 
 +
''<u>Pascal case for types (classes/interfaces/delegates/enums/structs) and methods:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af"><u>SomeClass</u></font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font><u>SomeMethod</u>() { }</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Camel case for member variables and parameters:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public void </font>MyMethod(<font color="#0000ff">int </font><u>someNumber</u>)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">int </font>''_number'';</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Camel case preceding by an underscore '_' for private/protected fields:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af"><u>SomeClass</u></font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">int </font>''_number'';</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">protected </font><font color="#0000ff">string </font>''_name'';</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Pascal case for enum's values:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">enum</font><font color="#2b91af">CodeReviewResult</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">None,</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">Approval,</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">PartialDisapproval,</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">CompleteDisapproval,</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">NeedRework,</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Must use Upper Case for naming constant and separate words with underscore character '_'
 +
 
 +
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public const int </font>DATABASE_CONNECTION_TIMEOUT = 500;</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Should not create namespaces, classes, methods, properties, fields, or parameters that vary only by capitalization.
 +
 
 +
''<u>Should not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font>MyMethod(<font color="#0000ff">string </font><font color="#ff0000">arg1</font>, <font color="#0000ff">string </font><font color="#ff0000">Arg1</font>)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Should not use names that begin with numeric characters.
 +
*Should not use single char variable names, except in <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">'''For/While'''</font> loop.
 +
*Always choose meaningful and specific names.
 +
*Should not use abbreviations unless the full name is excessive (over 20 characters). With Visual Studio IDE's IntelliSense, it is very easy finding a variable no matter how long the name is.
 +
 
 +
''<u>Should not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#2b91af">List</font>&lt;<font color="#0000ff">string</font>&gt; UDFList;</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font color="#ff0000">=&gt; this stands for User Defined list, the name hide the purpose of the owner variable from code reader</font>
 +
 
 +
==== Namespace naming ====
 +
 
 +
The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design.
 +
 
 +
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">namespace</font> CatGlobe.DiffStat.Console;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">namespace</font> CatGlobe.DiffStat.WinApp;</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
==== Type naming ====
 +
 
 +
*Use noun or pronoun for naming classes/interfaces.
 +
 
 +
''<u>Should not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af"><u>Run</u></font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Should:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af"><u>Runner</u></font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*MUST prefix an interface with character <font color="#ff0000"><font face="Courier New, monospace">I</font></font>.
 +
 
 +
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">int erface </font><font color="#ff0000">I</font><font color="#2b91af">SomeInterface</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*MUST suffix custom attribute classes with <font color="#ff0000"><font face="Courier New, monospace">Attribute</font></font>.
 +
 
 +
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">MyCustomAttribute</font>: System.<font color="#2b91af">Attribute</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*MUST suffix custom exeptions classes with <font color="#ff0000"><font face="Courier New, monospace">Exeption</font></font>.
 +
 
 +
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">My</font><font color="#2b91af">Exception</font>: System.<font color="#2b91af">Exception</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
===Naming===
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
====Common rules====
 
  
* Always use Camel Case or Pascal Case for naming. With private instance member, prefix variable name with an underscore '_'.
+
*MUST NOT suffix any enums with <font color="#ff0000"><font face="Courier New, monospace">Enum</font></font>.
''<U>Pascal case for types (classes/interfaces/delegates/enums/structs) and methods:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af"><U>SomeClass</U></FONT>
 
:{
 
::<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT><U>SomeMethod</U>() { }
 
:}
 
</FONT>
 
  
''<U>Camel case for member variables and parameters:</U>''
+
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public void </FONT>MyMethod(<FONT COLOR="#0000ff">int </FONT><U>someNumber</U>)
 
:{
 
::<FONT COLOR="#0000ff">int </FONT>''_number'';
 
:}
 
</FONT>
 
  
''<U>Camel case preceding by an underscore '_' for private/protected fields:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">enum </font><font color="#2b91af">ResourceType</font><font color="#ff0000">Enum</font><font color="#2b91af"></font><font color="#ff0000"><font face="Arial, sans-serif">=&gt; it is better if Enum is removed</font></font></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af"><U>SomeClass</U></FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
:{
 
::<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">int </FONT>''_number'';
 
::<FONT COLOR="#0000ff">protected </FONT><FONT COLOR="#0000ff">string </FONT>''_name'';
 
:}
 
</FONT>
 
  
''<U>Pascal case for enum's values:</U>''
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">enum</FONT><FONT COLOR="#2b91af">CodeReviewResult</FONT>
 
:{
 
::None,
 
::Approval,
 
::PartialDisapproval,
 
::CompleteDisapproval,
 
::NeedRework,
 
:}
 
</FONT>
 
  
* Must use Upper Case for naming constant and separate words with underscore character '_'
+
==== Method and Property naming ====
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public const int </FONT>DATABASE_CONNECTION_TIMEOUT = 500;
 
</FONT>
 
  
* Should not create namespaces, classes, methods, properties, fields, or parameters that vary only by capitalization.
+
*Use a verb-object pair for naming methods.
''<U>Should not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT>MyMethod(<FONT COLOR="#0000ff">string  </FONT><FONT COLOR="#ff0000">arg1</FONT>, <FONT COLOR="#0000ff">string </FONT><FONT COLOR="#ff0000">Arg1</FONT>)
 
:{
 
:}
 
</FONT>
 
  
* Should not use names that begin with numeric characters.
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
* Should not use single char variable names, except in <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">'''For/While'''</FONT> loop.
 
* Always choose meaningful and specific names.
 
* Should not use abbreviations unless the full name is excessive (over 20 characters). With Visual Studio IDE's IntelliSense, it is very easy finding a variable no matter how long the name is.
 
''<U>Should not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#2b91af">List</FONT>&lt;<FONT COLOR="#0000ff">string</FONT>&gt; UDFList;
 
</FONT>
 
:<FONT COLOR="#ff0000">=&gt; this stands for  User Defined list, the name hide the purpose of the owner variable from code reader</FONT>
 
  
====Namespace naming====
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font><u>Test</u>CatTask();</font>
The general rule for naming namespaces is to use
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font><u>Get</u>Name();</font>
the company name followed by the technology name and optionally the
 
feature and design.
 
  
''<U>Example:</U>''
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">namespace</FONT> CatGlobe.DiffStat.Console;
 
:<FONT COLOR="#0000ff">namespace</FONT> CatGlobe.DiffStat.WinApp;
 
</FONT>
 
  
====Type naming====
+
*If returned type is Boolean, try to prefix method name with “Can”, “Is” or “Has”.
  
* Use noun or pronoun for naming classes/interfaces.
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Should not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af"><U>Run</U></FONT>
 
:{
 
:}
 
</FONT>
 
  
''<U>Should:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">bool </font><u>Can</u>Save()</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">bool </font><u>Is</u>Editable()</font>
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af"><U>Runner</U></FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">bool </font><u>Has</u>Access()</font>
:{
 
:}
 
</FONT>
 
  
* MUST prefix an interface with character <FONT COLOR="#ff0000"><FONT FACE="Courier New, monospace">I</FONT></FONT>.
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">int erface </FONT><FONT COLOR="#ff0000">I</FONT><FONT COLOR="#2b91af">SomeInterface</FONT>
 
:{
 
:}
 
</FONT>
 
  
* MUST suffix custom attribute classes with <FONT COLOR="#ff0000"><FONT FACE="Courier New, monospace">Attribute</FONT></FONT>.
+
*Never perfix a property name with “Get”, “Set”. It is because when using value of a property it is already understand as calling to a “Get” method.
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">MyCustomAttribute</FONT>&#58; System.<FONT COLOR="#2b91af">Attribute</FONT>
 
:{
 
:}
 
</FONT>
 
  
* MUST suffix custom exeptions classes with <FONT COLOR="#ff0000"><FONT FACE="Courier New, monospace">Exeption</FONT></FONT>.
+
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">My</FONT><FONT COLOR="#2b91af">Exception</FONT>&#58; System.<FONT COLOR="#2b91af">Exception</FONT>
 
:{
 
:}
 
</FONT>
 
  
* MUST NOT suffix any enums with <FONT COLOR="#ff0000"><FONT FACE="Courier New, monospace">Enum</FONT></FONT>.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">int </font><font color="#ff0000">Get</font>IntValue { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }</font>
''<U>Must not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">enum </FONT><FONT COLOR="#2b91af">ResourceType</FONT><FONT COLOR="#ff0000">Enum</FONT><FONT COLOR="#2b91af"></FONT><FONT COLOR="#ff0000"><FONT FACE="Arial, sans-serif">=&gt; it is better if Enum is removed</FONT></FONT>
 
:{
 
:}
 
</FONT>
 
  
====Method and Property naming====
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
* Use a verb-object pair for naming methods.
+
''<u>Must:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT><U>Test</U>CatTask();  
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT><U>Get</U>Name();
 
</FONT>
 
  
* If returned type is Boolean, try to prefix method name with &ldquo;Can&rdquo;, &ldquo;Is&rdquo; or &ldquo;Has&rdquo;.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">int </font>IntValue { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }</font>
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">bool </FONT><U>Can</U>Save()
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">bool </FONT><U>Is</U>Editable()
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">bool </FONT><U>Has</U>Access()
 
</FONT>
 
  
* Never perfix a property name with &ldquo;Get&rdquo;, &ldquo;Set&rdquo;. It is because when using value of a property it is already understand as calling to a &ldquo;Get&rdquo; method.
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
''<U>Must not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">int </FONT><FONT COLOR="#ff0000">Get</FONT>IntValue { <FONT COLOR="#0000ff">get</FONT>; <FONT COLOR="#0000ff">set</FONT>; }
 
</FONT>
 
  
''<U>Must:</U>''
+
==== Generic types naming ====
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">int </FONT>IntValue { <FONT COLOR="#0000ff">get</FONT>; <FONT COLOR="#0000ff">set</FONT>; }
 
</FONT>
 
  
====Generic types naming====
+
*Should use single capital letters for generic types.
  
* Should use single capital letters for generic types.
+
''<u>Should:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Should:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">List</FONT>&lt;'''T'''&gt;<FONT COLOR="#0000ff"> where </FONT>'''T''' &#58; <FONT COLOR="#0000ff">string </FONT>
 
:{
 
:}
 
</FONT>
 
  
===Code organization===
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">List</font>&lt;'''T'''&gt;<font color="#0000ff">where </font>'''T''' : <font color="#0000ff">string </font></font>
====<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">using</FONT> Statement====
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
* All <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">using</FONT> statements should be put outside any namespaces statements.
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
''<U>Should:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.Web.UI.WebControls;
 
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.Web.Common.ClassBase;
 
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.Web.Common.ServerMethods;
 
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.Domain.SiteVisitor.ServiceHandler;
 
  
:<FONT COLOR="#0000ff">namespace </FONT>CatGlobe.Web.Common.Resources.List;
+
=== Code organization ===
:{
 
:}
 
</FONT>
 
  
''<U>Should not:</U>''
+
==== <font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">using</font> Statement ====
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">namespace </FONT>CatGlobe.Web.Common.Resources.List
 
:{
 
::<FONT COLOR="#0000ff">using </FONT>CatGlobe.Web.UI.WebControls;
 
::<FONT COLOR="#0000ff">using </FONT>CatGlobe.Web.Common.ClassBase;
 
::<FONT COLOR="#0000ff">using </FONT>CatGlobe.Web.Common.ServerMethods;
 
::<FONT COLOR="#0000ff">using </FONT>CatGlobe.Domain.SiteVisitor.ServiceHandler;
 
:}
 
</FONT>
 
  
* Related <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">using</FONT> statements should be group together. This helps reader an overview of which library will be used in the remaining code.
+
*All <font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">using</font> statements should be put outside any namespaces statements.
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">using </FONT>System;
 
:<FONT COLOR="#0000ff">using </FONT>System.Xml;
 
:<FONT COLOR="#0000ff">using </FONT>System.IO;
 
  
:<FONT COLOR="#0000ff">using </FONT>Infragistics.WebUI.UltraWebGrid; <FONT COLOR="#ff0000" FACE="Arial, sans-serif"> =&gt; Reference Infragistics</FONT>
+
''<u>Should:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
:<FONT COLOR="#0000ff">using </FONT>Infragistics.WebUI.UltraWebNavigator;
 
:<FONT COLOR="#0000ff">using </FONT>Infragistics.WebUI.UltraWebToolbar;
 
  
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.DataAccess;<FONT COLOR="#ff0000" FACE="Arial, sans-serif"> =&gt; Reference CatGlobe's DataAccess</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Web.UI.WebControls;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Web.Common.ClassBase;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Web.Common.ServerMethods;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Domain.SiteVisitor.ServiceHandler;</font>
  
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.Framework.GroupBuilder; <FONT COLOR="#ff0000" FACE="Arial, sans-serif"> =&gt; Reference CatGlobe's Framework</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">namespace </font>CatGlobe.Web.Common.Resources.List;</font>
:<FONT COLOR="#0000ff">using </FONT>CatGlobe.Framework.Resources;
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
====Internal Types====
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
* Types that are declared inside a class must be group together. And the group must be put right after class definition.
+
''<u>Should not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">ResourceList</FONT>
 
:{
 
::<FONT COLOR="#0000ff">#region </FONT>Types
 
  
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#808080">&lt;summary&gt;</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">namespace </font>CatGlobe.Web.Common.Resources.List</font>
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#008000">Collection of </FONT><FONT COLOR="#808080">&lt;seecref=&quot;CatGlobe.Domain.Common.Resource&quot;/&gt;</FONT><FONT COLOR="#008000">s,</FONT>
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#008000">in which we can sort the whole list or </FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Web.UI.WebControls;</font>
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#008000">fetch resources based on some criteria.</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Web.Common.ClassBase;</font>
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#808080">&lt;/summary&gt;</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Web.Common.ServerMethods;</font>
::<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">ResourceCollection</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Domain.SiteVisitor.ServiceHandler;</font>  
::{
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
::}
 
  
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#808080">&lt;summary&gt;</FONT>
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#008000">Provide methods for Save/Delete a single </FONT><FONT COLOR="#808080">&lt;seecref=&quot;CatGlobe.Domain.Common.Resource&quot;/&gt;</FONT>
 
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#008000">or collection of </FONT><FONT COLOR="#808080">&lt;see cref=&quot;CatGlobe.Domain.Common.Resource&quot;/&gt;</FONT><FONT COLOR="#008000">s.</FONT>
 
::<FONT COLOR="#808080">/// </FONT><FONT COLOR="#808080">&lt;/summary&gt;</FONT>
 
::<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">ResourceHandler</FONT>
 
::{
 
::}
 
  
::<FONT COLOR="#0000ff">#endregion </FONT>Types
+
*Related <font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">using</font> statements should be group together. This helps reader an overview of which library will be used in the remaining code.
:}
 
</FONT>
 
  
====Member and Local Variables====
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
* All class's member variable must be put at top of class (after internal types declaration). This increase readability of code, since at the first look the viewer can tell what are members of class and also theirs types.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>System;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>System.Xml;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>System.IO;</font>
  
* Each variable of different types must be declared on different lines.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>Infragistics.WebUI.UltraWebGrid; <font face="Arial, sans-serif" color="#ff0000">=&gt; Reference Infragistics</font></font>
''<U>Must:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>Infragistics.WebUI.UltraWebNavigator;</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>Infragistics.WebUI.UltraWebToolbar;</font>
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">string </FONT>_sampleString;
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">int </FONT>_sampleInt;
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">long </FONT>_sampleLong1, _sampleLong2, _sampleLong3;
 
</FONT>
 
  
''<U>Must not:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.DataAccess;<font face="Arial, sans-serif" color="#ff0000">=&gt; Reference CatGlobe's DataAccess</font></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">string </FONT>_sampleString;
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">int </FONT>_sampleInt;
 
</FONT>
 
  
* Local variables must be clared as close as possible to its first use and must be in the same code block that use it.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Framework.GroupBuilder; <font face="Arial, sans-serif" color="#ff0000">=&gt; Reference CatGlobe's Framework</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>CatGlobe.Framework.Resources;</font>
  
====Methods====
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
* A method must not exceed 100 lines. Methods with more than 100 lines usually decrease readability and thus maintainability.
+
==== Internal Types ====
  
* Methods that relate to each others by any means should be grouped together.
+
*Types that are declared inside a class must be group together. And the group must be put right after class definition.
''<U>Example:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">#region </FONT>Database Access Methods
 
:<FONT COLOR="#0000ff">#endregion </FONT>Database Access Methods
 
  
:<FONT COLOR="#0000ff">#region </FONT>Private Utility Methods
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
:<FONT COLOR="#0000ff">#endregion </FONT>Private Utility Methods
 
  
:<FONT COLOR="#0000ff">#region </FONT>Serialization Methods
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">ResourceList</font></font>
:<FONT COLOR="#0000ff">#endregion </FONT>Serialization Methods
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Types</font>
  
* Interface implementations must be grouped together.
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>
''<U>Example:</U>''
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">Collection of </font><font color="#808080">&lt;seecref="CatGlobe.Domain.Common.Resource"/&gt;</font><font color="#008000">s,</font></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">in which we can sort the whole list or </font></font>
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">interface </FONT><FONT COLOR="#2b91af">ISample</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">fetch resources based on some criteria.</font></font>
:{
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>
::<FONT COLOR="#0000ff">void </FONT>SampleMethod();
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">class </font><font color="#2b91af">ResourceCollection</font></font>
:}
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">SampleImplementation</FONT>&#58; <FONT COLOR="#2b91af">ISample</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;summary&gt;</font></font>
:{
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">Provide methods for Save/Delete a single </font><font color="#808080">&lt;seecref="CatGlobe.Domain.Common.Resource"/&gt;</font></font>
::<FONT COLOR="#0000ff">#region </FONT>ISample Members
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#008000">or collection of </font><font color="#808080">&lt;see cref="CatGlobe.Domain.Common.Resource"/&gt;</font><font color="#008000">s.</font></font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#808080">/// </font><font color="#808080">&lt;/summary&gt;</font></font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">class </font><font color="#2b91af">ResourceHandler</font></font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
::<FONT COLOR="#0000ff">void </FONT><FONT COLOR="#2b91af">ISample</FONT>.SampleMethod()
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Types</font>  
::{
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
::}
 
  
::<FONT COLOR="#0000ff">#endregion </FONT>ISample Members
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
:}
 
</FONT>
 
  
====Indentation deep====
+
==== Member and Local Variables ====
  
* All methods' indentation must not exceed a deep level of 3. Methods, whose indentation exceeds 3 in deep level, decrease readability, maintainability and also increase complexity.
+
*All class's member variable must be put at top of class (after internal types declaration). This increase readability of code, since at the first look the viewer can tell what are members of class and also theirs types.
''<U>Must not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">if </FONT>(HasAccess)
 
:{
 
::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>i = 0; i &lt; COUNT; i++)
 
::{
 
:::<FONT COLOR="#0000ff">if </FONT><FONT COLOR="#0000ff">(</FONT>list[i].IsTrue)
 
:::{
 
::::<FONT COLOR="#0000ff">switch </FONT> (resourceType)
 
::::<FONT COLOR="#ff0000">{</FONT>
 
:::::<FONT COLOR="#ff0000"><FONT FACE="Arial, sans-serif">=&gt; Code inside this block are too deep</FONT></FONT>
 
::::<FONT COLOR="#ff0000">}</FONT>
 
:::}
 
::}
 
:}
 
</FONT>
 
  
<DIV style="background: #c0c0c0; border: #000000 solid 1pt; padding: 5px; color: #0000ff">
+
*Each variable of different types must be declared on different lines.
'''Tips:'''
 
<BR />
 
There are 2 methods for reducing the deep level of code block:
 
  
* Reorganizing if statement
+
''<u>Must:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Original code:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT>SampleMethod(<FONT COLOR="#0000ff">bool </FONT>someCondition)
 
:{
 
::<FONT COLOR="#0000ff">if </FONT>(someCondition)
 
::{
 
:::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>i = 0; i &lt; COUNT; i++)
 
:::{
 
:::}
 
::}
 
:}
 
</FONT>
 
  
''<U>Changed code:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">string </font>_sampleString;</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">int </font>_sampleInt;</font>
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT>SampleMethod(<FONT COLOR="#0000ff">bool </FONT>someCondition)
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">long </font>_sampleLong1, _sampleLong2, _sampleLong3;</font>
:{
 
::<FONT COLOR="#0000ff">if </FONT> (!someCondition)
 
:::<FONT COLOR="#0000ff">return </FONT>;
 
::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>i = 0; i &lt; COUNT; i++)
 
::{
 
::}
 
:}
 
</FONT>
 
  
=&gt; The indentation's deep level has been decreased by 1.
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
  
* Creating private method
+
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Original code:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT>SampleMethod(<FONT COLOR="#0000ff">bool </FONT>someCondition)
 
:{
 
::<FONT COLOR="#0000ff">if </FONT>(HasAccess)
 
::{
 
:::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>i = 0; i &lt; COUNT; i++)
 
:::{
 
::::<FONT COLOR="#0000ff">if </FONT>(list[i].IsTrue)
 
::::{
 
:::::<FONT COLOR="#0000ff">foreach </FONT>(<FONT COLOR="#0000ff">int </FONT>value <FONT COLOR="#0000ff">in </FONT> list[i].Values)
 
:::::{
 
::::::<FONT COLOR="#0000ff">if </FONT>(value &gt; 0)
 
::::::{
 
:::::::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>j = 0; j &lt; value; j++)
 
:::::::{
 
::::::::<FONT COLOR="#0000ff">if </FONT>(anotherCondition)
 
::::::::{
 
::::::::}
 
:::::::}
 
::::::}
 
:::::}
 
::::}
 
:::}
 
::}
 
::}
 
</FONT>
 
  
''<U>Changed code:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">string </font>_sampleString;</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">int </font>_sampleInt;</font>
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">void </FONT>SampleMethod(<FONT COLOR="#0000ff">bool </FONT>someCondition)
 
:{
 
::<FONT COLOR="#0000ff">if </FONT>(HasAccess)
 
::{
 
:::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>i = 0; i &lt; COUNT; i++)
 
:::{
 
::::<FONT COLOR="#0000ff">if </FONT>(list[i].IsTrue)
 
::::{
 
:::::ProcessValues(list[i].Values);
 
::::}
 
:::}
 
::}
 
:} 
 
  
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">void </FONT>ProcessValues(<FONT COLOR="#2b91af">List</FONT>&lt;<FONT COLOR="#0000ff">int</FONT>&gt; values)
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
:{
 
::<FONT COLOR="#0000ff">foreach</FONT> (<FONT COLOR="#0000ff">int </FONT>value <FONT COLOR="#0000ff">in </FONT>values)
 
::{
 
:::<FONT COLOR="#0000ff">if </FONT>(value &gt; 0)
 
:::{
 
::::<FONT COLOR="#0000ff">for </FONT>(<FONT COLOR="#0000ff">int </FONT>j = 0; j &lt; value; j++)
 
::::{
 
:::::<FONT COLOR="#0000ff">if </FONT>(anotherCondition)
 
:::::{
 
:::::}
 
::::}
 
:::}
 
::}
 
:}
 
</FONT>
 
  
=&gt; The indentation's deep level is dreased more than 1
+
*Local variables must be clared as close as possible to its first use and must be in the same code block that use it.
  
</DIV>
+
==== Methods ====
  
====Attribute declaration====
+
*A method must not exceed 100 lines. Methods with more than 100 lines usually decrease readability and thus maintainability.
  
* For elements that have more than one Attribute declaration, then each <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">Attribute</FONT> must be put on one line.
+
*Methods that relate to each others by any means should be grouped together.
''<U>Must not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:[<FONT COLOR="#2b91af">Serializable</FONT>, <FONT COLOR="#2b91af">STAThread</FONT>, <FONT COLOR="#2b91af">Obsolete</FONT>(<FONT COLOR="#a31515">&quot;This class is obsolete. Use class Abc instead.&quot;</FONT>)]
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">SampleClass</FONT>
 
</FONT>
 
  
''<U>Must:</U>''
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:[<FONT COLOR="#2b91af">Serializable</FONT>]
 
:[<FONT COLOR="#2b91af">STAThread</FONT>]
 
:[<FONT COLOR="#2b91af">Obsolete</FONT>(<FONT COLOR="#a31515">&quot;This class is obsolete. Use class Abc instead.&quot;</FONT>)]
 
:<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">SampleClass</FONT>
 
</FONT>
 
  
==Coding guidelines==
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Database Access Methods</font>
===Basic language usage===
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Database Access Methods</font>
====Access modifier====
 
  
* All access modifier must be explicitly given, except in interface's declaration where <FONT COLOR="#0000ff"><FONT FACE="Courier New, monospace">public</FONT></FONT> is undertood by default.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Private Utility Methods</font>
''<U>Must not:</U>''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Private Utility Methods</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">SampleClass</FONT>
 
:{
 
::<FONT COLOR="#0000ff">int </FONT>sampleInt;
 
::<FONT COLOR="#0000ff">void </FONT>SampleMethod()
 
::{
 
::}
 
:}
 
</FONT>
 
  
====Variables and Types====
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>Serialization Methods</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>Serialization Methods</font>
  
* If possible, initialize variables at declaration time.
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
''<U>Should:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">int </FONT>primaryId = 0;
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#0000ff">string </FONT>sampleString = <FONT COLOR="#0000ff">string</FONT>.Empty;
 
:<FONT COLOR="#0000ff">private </FONT><FONT COLOR="#2b91af">List</FONT>&lt;<FONT COLOR="#0000ff">int</FONT>&gt; sampleList = <FONT COLOR="#0000ff">new</FONT> <FONT COLOR="#2b91af">List</FONT>&lt;<FONT COLOR="#0000ff">int</FONT>&gt;();
 
</FONT>
 
  
* Must use fully qualified name of types, declare the type by using statements. In case there are duplication in type's name, define aliases.
+
*Interface implementations must be grouped together.
''<U>Must not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#2b91af">ResourceCollectionPager</FONT> pager = CatGlobe.Framework.Services.<FONT COLOR="#2b91af">SessionManager</FONT>.Current.DataModule.Get&lt;<FONT COLOR="#2b91af">ResourceCollectionPager</FONT>&gt;(Request[<FONT COLOR="#a31515">&quot;sessionid&quot;</FONT>]);
 
</FONT>
 
  
''<U>Must:</U>''
+
''<u>Example:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">using</FONT> CatGlobe.Framework.Services;
 
:<FONT COLOR="#2b91af">ResourceCollectionPager</FONT> pager = <FONT COLOR="#2b91af">SessionManager</FONT>.Current.DataModule.Get&lt;<FONT COLOR="#2b91af">ResourceCollectionPager</FONT>&gt;(Request[<FONT COLOR="#a31515">&quot;sessionid&quot;</FONT>]);
 
</FONT>
 
  
<DIV style="background: #c0c0c0; border: #000000 solid 1pt; padding: 5px; color: #0000ff;">
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">interface </font><font color="#2b91af">ISample</font></font>
'''Tips:'''
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
<BR />
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">void </font>SampleMethod();</font>
Always choose &ldquo;using&rdquo; over fully qualified name from Resolve menu of Visual Studio.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
[[Image: Coding_Guidelines_Common_rules_1.0_html_m6738e672.png|400px||center|Resolve menu of VS2008]]
 
</DIV>
 
 
''<U>Example of using alias:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">using </FONT>Threading = System.Threading;
 
:<FONT COLOR="#0000ff">using </FONT>Timers = System.Timers;
 
:<FONT COLOR="#0000ff">using </FONT>Web = System.Web.UI;
 
  
:<FONT COLOR="#0000ff">namespace</FONT>CatGlobe.DataAccess
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleImplementation</font>: <font color="#2b91af">ISample</font></font>
:{
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
::<FONT COLOR="#0000ff">public </FONT><FONT COLOR="#0000ff">class </FONT><FONT COLOR="#2b91af">SampleClass</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#region </font>ISample Members</font>
::{
 
:::<FONT COLOR="#0000ff">private </FONT>Threading.<FONT COLOR="#2b91af">Timer</FONT> _threadTimer1;
 
:::<FONT COLOR="#0000ff">private </FONT>Timers.<FONT COLOR="#2b91af">Timer</FONT> _threadTimer2;
 
:::<FONT COLOR="#0000ff">private </FONT>Web.<FONT COLOR="#2b91af">Timer</FONT> _threadTimer3;
 
::}
 
:}
 
</FONT>
 
  
====Constants and Literals====
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">void </font><font color="#2b91af">ISample</font>.SampleMethod()</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
* Never hardcoded strings that will be presented to end-users. Use <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#33a3a3">Resoures</FONT> class instead.
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">#endregion </font>ISample Members</font>  
''<U>Must not</U>'':
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">&lt;</FONT><FONT COLOR="#a31515">span</FONT><FONT COLOR="#0000ff">&gt;</FONT>Username<FONT COLOR="#0000ff">&lt;/</FONT><FONT COLOR="#a31515">span</FONT><FONT COLOR="#0000ff">&gt;</FONT>
 
</FONT>
 
  
''<U>Must</U>'':
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">&lt;</FONT><FONT COLOR="#a31515">span</FONT><FONT COLOR="#0000ff">&gt;</FONT>&lt;%<FONT COLOR="#0000ff">=</FONT>Resources.Username %&gt;<FONT COLOR="#0000ff">&lt;/</FONT><FONT COLOR="#a31515">span</FONT><FONT COLOR="#0000ff">&gt;</FONT>
 
</FONT>
 
  
* Try to use @ instead escape characters symbol
+
==== Indentation deep ====
''<U>Should:</U>''
 
:<FONT COLOR="#0000ff">string </FONT>filename = <FONT COLOR="#a31515">@&quot;D:\test\test.xml&quot;</FONT>;
 
  
====Direct cast vs. <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">as</FONT> keyword====
+
*All methods' indentation must not exceed a deep level of 3. Methods, whose indentation exceeds 3 in deep level, decrease readability, maintainability and also increase complexity.
Following code block:
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#2b91af">CustomClass</FONT> a = src <FONT COLOR="#0000ff"> as </FONT><FONT COLOR="#2b91af">CustomClass</FONT>;
 
</FONT>
 
  
can be considered the same as the code block below:
+
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">if </FONT>(src <FONT COLOR="#0000ff">is</FONT> <FONT COLOR="#2b91af">CustomClass</FONT>)
 
::<FONT COLOR="#0000ff">return </FONT>(<FONT COLOR="#2b91af">CustomClass</FONT>)src;
 
:else
 
::<FONT COLOR="#0000ff">return </FONT><FONT COLOR="#0000ff">null</FONT>;
 
</FONT>
 
  
Consequently, it is encouraged to use <FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">as</FONT>  
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(HasAccess)</font>
keyword over directcasting, because it is neat and safer.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>i = 0; i &lt; COUNT; i++)</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font><font color="#0000ff">(</font>list[i].IsTrue)</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">switch </font> (resourceType)</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#ff0000">{</font> </font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#ff0000"><font face="Arial, sans-serif">=&gt; Code inside this block are too deep</font></font></font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#ff0000">}</font></font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
  
===Exceptions handling===
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
<div style="border: 1pt solid rgb(0, 0, 0); padding: 5px; background: rgb(192, 192, 192) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 255);">
 +
'''Tips:''' <br> There are 2 methods for reducing the deep level of code block:
  
* Catch least generic exception first
+
*Reorganizing if statement
''<U>Must not:</U>''
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">try</FONT>
 
:{
 
::<FONT COLOR="#0000ff">using </FONT>(<FONT COLOR="#2b91af">FileStream</FONT> fs = <FONT COLOR="#0000ff">new</FONT><FONT COLOR="#2b91af">FileStream</FONT>(<FONT COLOR="#a31515">@&quot;</FONT>D:\test.xml<FONT COLOR="#a31515">&quot;</FONT>)) { }
 
:}
 
:<FONT COLOR="#0000ff">catch </FONT> (<FONT COLOR="#2b91af">Exception</FONT>) { }
 
:<FONT COLOR="#0000ff">catch </FONT> (<FONT COLOR="#2b91af">IOException</FONT>)
 
:{
 
::<FONT COLOR="#ff0000" FACE="Arial">=&gt;Unreachable code</FONT>
 
:}
 
</FONT>
 
  
* Do not use exception for controlling flows, instead try to validate input parameter. Most of the time exceptions can be prevented by proper input validation.
+
''<u>Original code:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
''<U>Should not</U>'':
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">string </FONT>input = <FONT COLOR="#a31515">&quot;something&quot;</FONT>;
 
:<FONT COLOR="#0000ff">try</FONT>
 
:{
 
::DoWork(input);
 
:}
 
:<FONT COLOR="#0000ff">catch </FONT>(<FONT COLOR="#2b91af">Exception</FONT> e)
 
:{
 
::DoAlternateWork(input);
 
:}
 
</FONT>
 
  
* All exception must be re-thrown, the outest layer (usually GUI win-form or web-form) must responsible for handling the exception properly.
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font>SampleMethod(<font color="#0000ff">bool </font>someCondition)</font>
''<U>Must not</U>'':
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(someCondition)</font>
:<FONT COLOR="#0000ff">try</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
:{
+
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>i = 0; i &lt; COUNT; i++)</font>
::DoWork();
+
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
:}
+
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
:<FONT COLOR="#0000ff">catch </FONT>(<FONT COLOR="#2b91af">Exception</FONT> e)
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>  
:{
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
::<FONT COLOR="#008000">// do nothing</FONT>
 
:}
 
</FONT>
 
  
* If not creating a wrapper exception, use &ldquo;<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">throw</FONT>&rdquo; instead of &ldquo;<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">throw</FONT><FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000"> e</FONT>&rdquo; to reserve the call-stack. &ldquo;<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">throw</FONT>&rdquo; statement's stack trace points to the code place that actually causes the error, while &ldquo;<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">throw</FONT><FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000"> e</FONT>&rdquo;'s stack trace points to the location of the &ldquo;<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#0000ff">throw</FONT><FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000"> e</FONT>&rdquo; statement only. 
+
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>  
''<U>Must not</U>'':
 
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">catch </FONT>(<FONT COLOR="#2b91af">IOException</FONT> ioe)
 
:{
 
::<FONT COLOR="#2b91af">Logger</FONT>.LogError(ioe);
 
::<FONT COLOR="#0000ff">throw </FONT>ioe; <FONT COLOR="#ff0000"><FONT FACE="Arial, sans-serif"> =&gt; Must be</FONT> throw;</FONT>
 
:}
 
</FONT>
 
  
''<U>Correct</U>'':
+
''<u>Changed code:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
<FONT FACE="Courier New, monospace" SIZE=2 STYLE="font-size: 9pt" COLOR="#000000">
 
:<FONT COLOR="#0000ff">catch </FONT>(<FONT COLOR="#2b91af">IOException</FONT> ioe)
 
:{
 
::<FONT COLOR="#2b91af">Logger</FONT>.LogError(ioe);
 
::<FONT COLOR="#0000ff">throw </FONT><FONT COLOR="#0000ff">new </FONT><FONT COLOR="#2b91af">CustomeException</FONT>(<FONT COLOR="#a31515">&quot;error&quot;</FONT>, ioe);
 
:}
 
  
:<FONT COLOR="#0000ff">catch </FONT>(<FONT COLOR="#2b91af">IOException</FONT> ioe)
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font>SampleMethod(<font color="#0000ff">bool </font>someCondition)</font>
:{
+
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
::<FONT COLOR="#2b91af">Logger</FONT>.LogError(ioe);
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font> (!someCondition) </font>
::<FONT COLOR="#0000ff">throw</FONT>;
+
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">return </font>;</font>
:}
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>i = 0; i &lt; COUNT; i++)</font>
</FONT>
+
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
=&gt; The indentation's deep level has been decreased by 1.
 +
 
 +
*Creating private method
 +
 
 +
''<u>Original code:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font>SampleMethod(<font color="#0000ff">bool </font>someCondition)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(HasAccess)</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>i = 0; i &lt; COUNT; i++)</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(list[i].IsTrue)</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">foreach </font>(<font color="#0000ff">int </font>value <font color="#0000ff">in </font> list[i].Values)</font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(value &gt; 0)</font>
 +
::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>j = 0; j &lt; value; j++)</font>
 +
:::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(anotherCondition)</font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Changed code:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">void </font>SampleMethod(<font color="#0000ff">bool </font>someCondition)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(HasAccess)</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>i = 0; i &lt; COUNT; i++)</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(list[i].IsTrue)</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">ProcessValues(list[i].Values);</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">void </font>ProcessValues(<font color="#2b91af">List</font>&lt;<font color="#0000ff">int</font>&gt; values)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">foreach</font> (<font color="#0000ff">int </font>value <font color="#0000ff">in </font>values)</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(value &gt; 0)</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">for </font>(<font color="#0000ff">int </font>j = 0; j &lt; value; j++)</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(anotherCondition)</font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
:::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
=&gt; The indentation's deep level is dreased more than 1
 +
</div>
 +
==== Attribute declaration ====
 +
 
 +
*For elements that have more than one Attribute declaration, then each <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">Attribute</font> must be put on one line.
 +
 
 +
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">[<font color="#2b91af">Serializable</font>, <font color="#2b91af">STAThread</font>, <font color="#2b91af">Obsolete</font>(<font color="#a31515">"This class is obsolete. Use class Abc instead."</font>)]</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Must:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">[<font color="#2b91af">Serializable</font>]</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">[<font color="#2b91af">STAThread</font>]</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">[<font color="#2b91af">Obsolete</font>(<font color="#a31515">"This class is obsolete. Use class Abc instead."</font>)]</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
== Coding guidelines ==
 +
 
 +
=== Basic language usage ===
 +
 
 +
==== Access modifier ====
 +
 
 +
*All access modifier must be explicitly given, except in interface's declaration where <font color="#0000ff"><font face="Courier New, monospace">public</font></font> is undertood by default.
 +
 
 +
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">int </font>sampleInt;</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">void </font>SampleMethod()</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
==== Variables and Types ====
 +
 
 +
*If possible, initialize variables at declaration time.
 +
 
 +
''<u>Should:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">int </font>primaryId = 0;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#0000ff">string </font>sampleString = <font color="#0000ff">string</font>.Empty;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font><font color="#2b91af">List</font>&lt;<font color="#0000ff">int</font>&gt; sampleList = <font color="#0000ff">new</font> <font color="#2b91af">List</font>&lt;<font color="#0000ff">int</font>&gt;();</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Must use fully qualified name of types, declare the type by using statements. In case there are duplication in type's name, define aliases.
 +
 
 +
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">ResourceCollectionPager</font> pager = CatGlobe.Framework.Services.<font color="#2b91af">SessionManager</font>.Current.DataModule.Get&lt;<font color="#2b91af">ResourceCollectionPager</font>&gt;(Request[<font color="#a31515">"sessionid"</font>]);</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Must:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using</font> CatGlobe.Framework.Services;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">ResourceCollectionPager</font> pager = <font color="#2b91af">SessionManager</font>.Current.DataModule.Get&lt;<font color="#2b91af">ResourceCollectionPager</font>&gt;(Request[<font color="#a31515">"sessionid"</font>]);</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
<div style="border: 1pt solid rgb(0, 0, 0); padding: 5px; background: rgb(192, 192, 192) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 255);">
 +
'''Tips:''' <br> Always choose “using” over fully qualified name from Resolve menu of Visual Studio. [[Image:Coding Guidelines Common rules 1.0 html m6738e672.png|center|400px|Resolve menu of VS2008]]
 +
</div>
 +
''<u>Example of using alias:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>Threading = System.Threading;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>Timers = System.Timers;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>Web = System.Web.UI;</font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">namespace</font>CatGlobe.DataAccess</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">public </font><font color="#0000ff">class </font><font color="#2b91af">SampleClass</font></font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font>Threading.<font color="#2b91af">Timer</font> _threadTimer1;</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font>Timers.<font color="#2b91af">Timer</font> _threadTimer2;</font>
 +
:::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">private </font>Web.<font color="#2b91af">Timer</font> _threadTimer3;</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
==== Constants and Literals ====
 +
 
 +
*Never hardcoded strings that will be presented to end-users. Use <font face="Courier New, monospace" size="2" color="#33a3a3" style="font-size: 9pt;">Resoures</font> class instead.
 +
 
 +
''<u>Must not</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">&lt;</font><font color="#a31515">span</font><font color="#0000ff">&gt;</font>Username<font color="#0000ff">&lt;/</font><font color="#a31515">span</font><font color="#0000ff">&gt;</font></font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Must</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">&lt;</font><font color="#a31515">span</font><font color="#0000ff">&gt;</font>&lt;%<font color="#0000ff">=</font>Resources.Username&nbsp;%&gt;<font color="#0000ff">&lt;/</font><font color="#a31515">span</font><font color="#0000ff">&gt;</font></font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Try to use @ instead escape characters symbol
 +
 
 +
''<u>Should:</u>''
 +
 
 +
:<font color="#0000ff">string </font>filename = <font color="#a31515">@"D:\test\test.xml"</font>;
 +
 
 +
==== Direct cast vs. <font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">as</font> keyword ====
 +
 
 +
Following code block: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">CustomClass</font> a = src <font color="#0000ff">as </font><font color="#2b91af">CustomClass</font>;</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
can be considered the same as the code block below: <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">if </font>(src <font color="#0000ff">is</font> <font color="#2b91af">CustomClass</font>) </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">return </font>(<font color="#2b91af">CustomClass</font>)src;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">else </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">return </font><font color="#0000ff">null</font>;</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
Consequently, it is encouraged to use <font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">as</font> keyword over directcasting, because it is neat and safer.
 +
 
 +
=== Exceptions handling ===
 +
 
 +
*Catch least generic exception first
 +
 
 +
''<u>Must not:</u>'' <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">try</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">using </font>(<font color="#2b91af">FileStream</font> fs = <font color="#0000ff">new</font><font color="#2b91af">FileStream</font>(<font color="#a31515">@"</font>D:\test.xml<font color="#a31515">"</font>)) { }</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font> (<font color="#2b91af">Exception</font>) { }</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font> (<font color="#2b91af">IOException</font>)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font face="Arial" color="#ff0000">=&gt;Unreachable code</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*Do not use exception for controlling flows, instead try to validate input parameter. Most of the time exceptions can be prevented by proper input validation.
 +
 
 +
''<u>Should not</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">string </font>input = <font color="#a31515">"something"</font>;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">try</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">DoWork(input);</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font>(<font color="#2b91af">Exception</font> e)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">DoAlternateWork(input);</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*All exception must be re-thrown, the outest layer (usually GUI win-form or web-form) must responsible for handling the exception properly.
 +
 
 +
''<u>Must not</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">try</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">DoWork();</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font>(<font color="#2b91af">Exception</font> e)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#008000">// do nothing</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
*If not creating a wrapper exception, use “<font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">throw</font>” instead of “<font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">throw</font><font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">e</font>” to reserve the call-stack. “<font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">throw</font>” statement's stack trace points to the code place that actually causes the error, while “<font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">throw</font><font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">e</font>”'s stack trace points to the location of the “<font face="Courier New, monospace" size="2" color="#0000ff" style="font-size: 9pt;">throw</font><font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">e</font>” statement only.
 +
 
 +
''<u>Must not</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font>(<font color="#2b91af">IOException</font> ioe)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">Logger</font>.LogError(ioe);</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">throw </font>ioe; <font color="#ff0000"><font face="Arial, sans-serif">=&gt; Must be</font> throw;</font></font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
''<u>Correct</u>'': <font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font>(<font color="#2b91af">IOException</font> ioe)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">Logger</font>.LogError(ioe);</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">throw </font><font color="#0000ff">new </font><font color="#2b91af">CustomeException</font>(<font color="#a31515">"error"</font>, ioe);</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">catch </font>(<font color="#2b91af">IOException</font> ioe)</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">{ </font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#2b91af">Logger</font>.LogError(ioe);</font>
 +
::<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"><font color="#0000ff">throw</font>;</font>
 +
:<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;">}</font>
 +
 
 +
<font face="Courier New, monospace" size="2" color="#000000" style="font-size: 9pt;"></font>
 +
 
 +
== Document revisions ==
  
==Document revisions==
 
 
{|
 
{|
| '''Version No.''' || '''Date''' || '''Changed By''' || '''Description'''
 
 
|-
 
|-
| 0.1
+
| '''Version No.'''
| 10.07.2008
+
| '''Date'''
| Nguyen Trung Chinh
+
| '''Changed By'''
 +
| '''Description'''
 +
|-
 +
| 0.1  
 +
| 10.07.2008  
 +
| Nguyen Trung Chinh  
 
| Copy from http://blogs.msdn.com/brada/articles/361363.aspx
 
| Copy from http://blogs.msdn.com/brada/articles/361363.aspx
 
|-
 
|-
| 0.1
+
| 0.1  
| 22.08.2008
+
| 22.08.2008  
| Nguyen Trung Chinh
+
| Nguyen Trung Chinh  
 
| Refine from original document, add more applicable rules
 
| Refine from original document, add more applicable rules
 
|-
 
|-
| 0.1
+
| 0.1  
| 25.08.2008
+
| 25.08.2008  
| Nguyen Trung Chinh
+
| Nguyen Trung Chinh  
 
| Fix for 0.1 after reviews of Dennis and Thuan
 
| Fix for 0.1 after reviews of Dennis and Thuan
 
|-
 
|-
| 0.2
+
| 0.2  
| 08.10.2008
+
| 08.10.2008  
| Nguyen Trung Chinh
+
| Nguyen Trung Chinh  
 
| Add section 3.5 and 4
 
| Add section 3.5 and 4
 
|-
 
|-
| 0.3
+
| 0.3  
| 13.10.2008
+
| 13.10.2008  
| Nguyen Trung Chinh
+
| Nguyen Trung Chinh  
 
| Finish section 4
 
| Finish section 4
 
|-
 
|-
| 1.0
+
| 1.0  
| 14.11.2008
+
| 14.11.2008  
| Nguyen Trung Chinh
+
| Nguyen Trung Chinh  
 
| Finalize version 1.0
 
| Finalize version 1.0
 
|}
 
|}
 +
 +
[[Category:Technical guidelines]]

Latest revision as of 05:39, 18 October 2013

<accesscontrol>Main:MyGroup</accesscontrol>

Introduction

This document aims at giving common rules that developers MUST follow to ensure not only consistency in the whole application but also the ease of code reading and maintaining. Due to the fact that we are working mainly on C# language, all examples will be given in this language only.

Please refer to the .NET Framework Design Guidelines (http://msdn.microsoft.com/en-us/library/czefa0ke.aspx) for a complete set of guidelines suggested by Microsoft.

Terms and Conventions

Naming Terms

There are 3 terms used for naming files, class names, variable names, etc. All are listed in this section.

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: CatGlobeImageButton, LanguageEditor

Camel case

The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.

For example: resourceId, resourceTemplateId

Uppercase All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters.

For example: ID, UI, IO

Style Guidelines

File Organization

Location

  • Class file should be put in directory whose path follows class's namespace. This makes finding a class easier.

For example: code file of class CatGlobe.Web.UI.WebControls.CatGlobeImageButton should be found in side {CODE_BASE}\CatGlobe\Web\UI\WebControls

Naming

  • Always use Pascal for naming code file.
  • Source files should be given the name of the first public class in the file plus “.cs”. The purpose of this naming is clear, it increases the consistent of organization and also the maintainability.

For example: code file {CODE_BASE}\CatGlobe\Web\UI\WebControls\CatGlobeImageButton.cs should have the first public class as CatGlobeImageButton

Content

  • There should be only one namespace declaration in one code file only.
  • One source file should contain only one public class/interface/enum, although multiple internal classes are allowed. Delegates and Interfaces are allowed to be put in the same file as class/interface/enum.

Should

public sealed class CatTask : PersistentObject, ICatTaskClientObject, IComparable
{
private sealed class CatTasksAccess : AccessBase
{
}
}

Should not

public sealed class CatTask : PersistentObject, ICatTaskClientObject, IComparable
{
}
[Serializable]
public sealed class StringConstant
{
}

  • Classes member should be grouped into sections (Fields, Constructors, Properties, Events, Methods, Private interface implementations, Nested types). And there should be a region name in #endregion instructive although it is not required. Regions can be shown/hide while viewing with VS thus increasing the readability.

For example:

public sealed class CatTask : PersistentObject, ICatTaskClientObject, IComparable
{
#region AccessClass
private sealed class CatTasksAccess : AccessBase
{
}
#endregion AccessClass
#region Private Instance Fields
private int resourceId;
private int resourceTemplateId;
#endregion Private Instance Fields
}

A propose class file with regions:

public class SampleClass
{
#region Nested Enums, Structs, and Classes
#endregion Nested Enums, Structs, and Classes
#region Constructors & Finalizers
#endregion Constructors & Finalizers
#region Member variables
#endregion Member variables
#region roperties
#endregion Properties
#region Methods
#endregion Methods
}

  • There should not be more than 500 lines of code inside one file. Files containing more than 500 lines have less readability than the ones with less than 500 lines. There is one exception that we should not take into account on this rules, that are auto-generated files since most of the time we do not maintain these files directly.
  • Each line of code should not exceed 120 characters. Lines with more than 120 characters normally require code viewer using the horizontal scrollbar thus decrease readability.

Tabs, Indenting, Spacing and Bracing

Tabs and Indenting

  • Tab characters (\0x09) MUST NOT be used in code. All tabs must be replaced by 3 space characters.
  • All indentation MUST be done with 3 space characters.

Spacing Spaces improve readability by decreasing code density. Here are some guidelines for the use of space characters within code:

  • Do use a single space after a comma between function arguments.
Right:Console.In.Read(myChar,0,1);
Wrong: Console.In.Read(myChar,0,1);
  • Do not use a space after the parenthesis and function arguments.
Right: CreateFoo(myChar, 0, 1);
Wrong: CreateFoo( myChar, 0, 1 )
  • Do notuse spaces between a function name and parenthesis.
Right: CreateFoo();
Wrong: CreateFoo ()
  • Do notuse spaces inside brackets.
Right: x = dataArray[index];
Wrong: x = dataArray[ index ];
  • Do use a single space before flow control statements.
Right: while (x == y)
Wrong: while(x==y)
  • Do use a single space before and after comparison operators.
Right: if (x == y)
Wrong: if (x==y)

Bracing

  • Open braces must always be at the beginning of the line after the statement that begins the block. This increases readability of code.

Must:

if ((CatTaskStatus.Status == CatTaskCommon.CatTaskStatus.Failed)
{
CatTaskCompleted ctc = CatTaskCompleted.GetByLatestCompletedDate(this);
if (ctc != null)
completedDate = ctc.CompletedDate;
return completedDate;
}
else
{
...
}

Must not:

if ((CatTaskStatus.Status == CatTaskCommon.CatTaskStatus.Failed) {=> Wrong brace's location
CatTaskCompleted ctc = CatTaskCompleted.GetByLatestCompletedDate(this);
if (ctc != null) {
completedDate = ctc.CompletedDate;
}
return completedDate;
}

  • For anonymous methods and lambda expressions, the braces must be indent at the same level with its declaration.

Example:

private SampleDelegate _mySampleDelegate = delegate()
   {
   };
private SampleDelegate _mySampleDelegate = (name) =>
   {
   };

  • Must not put block that contains more than 2 statements in the same line:

Must not:

if (ctc != null) {completedDate = ctc.CompletedDate; return completedDate; }

  • With single statement blocks, using of braces is optionnal. It is encourage to not use the braces to save number of line of code.

Should:

if (ctc != null)
completedDate = ctc.CompletedDate;

Should not:

if (ctc != null)
{
completedDate = ctc.CompletedDate; => 3 lines of code do the same as 1 line
}

  • There are exceptions that brace should be placed on the same line as the keyword that requires braces.

One statement code block:

public int CompletedMailTemplateId
{
get { return completedMailTemplateId; } => It is much nicer than having 4 lines of code
set { completedMailTemplateId = value; }
}

.NET 3.0 property syntax:

public int MyProperty { get; set; }

Tips:
All rules in this section can be applied automatically by applying a common Visual Studio settings file. Developers just have to remember to apply these rules by pressing Ctrl + K + D (under default installation) or Ctrl + E + C using Resharper before committing.

Commenting

Comments should be used to describe intention, algorithmic overview, and/or logical flow. It would be ideal, if from reading the comments alone, someone other than the author could understand a function’s intended behavior and general operation. While there are no minimum comment requirements and certainly some very small routines need no commenting at all, it is hoped that most routines will have comments reflecting the programmer’s intent and approach.

  • Use // or /// for commenting but not /* ... */. The last comment style is out of date, it is useful in the old time when coder wanted to comment a large block of code. Using such comment will save a lot of time as writing // on each line. However, with new editor, comment/uncomment block of code is just a matter of selecting the block and calling a short cut key.
  • Do not decorate your comment with special charaters.

Must not:

// *********************************
// Comments block
// **********************************

  • Avoid comments that explain the obvious. Code should be self-explanatory. Good code with readable variable and method names should not require comments.

Should not

/// <summary>
/// Resource Id
/// </summary>
private int resourceId;

=> Comment that makes no sense. Could be something like: <The primary id of the <see cref=”CatGlobe.Domain.Common.Resource” /> that this class is working with.
  • Include Task-List keywords flags to enable comment-filtering. These comment can be tracked by using Visual Studio Task List window or just simply by searching.

Example:

// TODO: Fix this
// HACK: work-around temporarily while waiting for better solution
// UNDONE: Will be done in version xxxx

Tips:
In Visual Studio, more keywords can be defined in Tools Environment → Task List. More detail description can be found here http://msdn.microsoft.com/en-us/library/zce12xx2(VS.80).aspx

  • Always apply C# comment-blocks (///) to public, protected and internal declaration. The comment will be displayed as tooltip in editor and this helps method's user a lot for writing code correctly.

See picture below:

Class comment displayed inside help text


  • Use comment tags whenever possible, this could give very much help on generating help files. The most used tags are: <summary>, <param>, <paramref>, <return>, <exception>, <see>, <seeAlso>.

Class comment:

/// <summary>
/// This is my sample class for illustating comment on coding guide line document
/// </summary>
public class SampleClass
{
}

Method comment:

/// <summary>
/// This is my test method. It is created for demonstrating how to write comment for
/// a method.
/// </summary>
/// <param name="arg1">This is sample argument 1. It will be used for ... </param>
/// <param name="arg2">This is sample argument 2. It will be used for ...</param>
/// <returns>Return the result string.</returns>
protected string MyMethod(string arg1, string arg2)
{
}

Tips:
In Visual Studio, typing three slashes on the line right before a declaration will automatically create a template for comment on the correspondence element.

An explaination on the comment can be found here: http://msdn.microsoft.com/en-us/magazine/cc302121.aspx

A detail explaination of all comment tags can be found here: http://thoughtpad.net/alan-dean/cs-xml-documentation.

Naming

Common rules

  • Always use Camel Case or Pascal Case for naming. With private instance member, prefix variable name with an underscore '_'.

Pascal case for types (classes/interfaces/delegates/enums/structs) and methods:

public class SomeClass
{
public void SomeMethod() { }
}

Camel case for member variables and parameters:

public void MyMethod(int someNumber)
{
int _number;
}

Camel case preceding by an underscore '_' for private/protected fields:

public class SomeClass
{
private int _number;
protected string _name;
}

Pascal case for enum's values:

public enumCodeReviewResult
{
None,
Approval,
PartialDisapproval,
CompleteDisapproval,
NeedRework,
}

  • Must use Upper Case for naming constant and separate words with underscore character '_'

Example:

public const int DATABASE_CONNECTION_TIMEOUT = 500;

  • Should not create namespaces, classes, methods, properties, fields, or parameters that vary only by capitalization.

Should not:

public void MyMethod(string arg1, string Arg1)
{
}

  • Should not use names that begin with numeric characters.
  • Should not use single char variable names, except in For/While loop.
  • Always choose meaningful and specific names.
  • Should not use abbreviations unless the full name is excessive (over 20 characters). With Visual Studio IDE's IntelliSense, it is very easy finding a variable no matter how long the name is.

Should not:

public List<string> UDFList;

=> this stands for User Defined list, the name hide the purpose of the owner variable from code reader

Namespace naming

The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design.

Example:

namespace CatGlobe.DiffStat.Console;
namespace CatGlobe.DiffStat.WinApp;

Type naming

  • Use noun or pronoun for naming classes/interfaces.

Should not:

public class Run
{
}

Should:

public class Runner
{
}

  • MUST prefix an interface with character I.

Example:

public int erface ISomeInterface
{
}

  • MUST suffix custom attribute classes with Attribute.

Example:

public class MyCustomAttribute: System.Attribute
{
}

  • MUST suffix custom exeptions classes with Exeption.

Example:

public class MyException: System.Exception
{
}

  • MUST NOT suffix any enums with Enum.

Must not:

public enum ResourceTypeEnum=> it is better if Enum is removed
{
}

Method and Property naming

  • Use a verb-object pair for naming methods.

Example:

public void TestCatTask();
public void GetName();

  • If returned type is Boolean, try to prefix method name with “Can”, “Is” or “Has”.

Example:

public bool CanSave()
public bool IsEditable()
public bool HasAccess()

  • Never perfix a property name with “Get”, “Set”. It is because when using value of a property it is already understand as calling to a “Get” method.

Must not:

public int GetIntValue { get; set; }

Must:

public int IntValue { get; set; }

Generic types naming

  • Should use single capital letters for generic types.

Should:

public class List<T>where T : string
{
}

Code organization

using Statement

  • All using statements should be put outside any namespaces statements.

Should:

using CatGlobe.Web.UI.WebControls;
using CatGlobe.Web.Common.ClassBase;
using CatGlobe.Web.Common.ServerMethods;
using CatGlobe.Domain.SiteVisitor.ServiceHandler;
namespace CatGlobe.Web.Common.Resources.List;
{
}

Should not:

namespace CatGlobe.Web.Common.Resources.List
{
using CatGlobe.Web.UI.WebControls;
using CatGlobe.Web.Common.ClassBase;
using CatGlobe.Web.Common.ServerMethods;
using CatGlobe.Domain.SiteVisitor.ServiceHandler;
}

  • Related using statements should be group together. This helps reader an overview of which library will be used in the remaining code.

Example:

using System;
using System.Xml;
using System.IO;
using Infragistics.WebUI.UltraWebGrid; => Reference Infragistics
using Infragistics.WebUI.UltraWebNavigator;
using Infragistics.WebUI.UltraWebToolbar;
using CatGlobe.DataAccess;=> Reference CatGlobe's DataAccess
using CatGlobe.Framework.GroupBuilder; => Reference CatGlobe's Framework
using CatGlobe.Framework.Resources;

Internal Types

  • Types that are declared inside a class must be group together. And the group must be put right after class definition.

Example:

public class ResourceList
{
#region Types
/// <summary>
/// Collection of <seecref="CatGlobe.Domain.Common.Resource"/>s,
/// in which we can sort the whole list or
/// fetch resources based on some criteria.
/// </summary>
private class ResourceCollection
{
}
/// <summary>
/// Provide methods for Save/Delete a single <seecref="CatGlobe.Domain.Common.Resource"/>
/// or collection of <see cref="CatGlobe.Domain.Common.Resource"/>s.
/// </summary>
private class ResourceHandler
{
}
#endregion Types
}

Member and Local Variables

  • All class's member variable must be put at top of class (after internal types declaration). This increase readability of code, since at the first look the viewer can tell what are members of class and also theirs types.
  • Each variable of different types must be declared on different lines.

Must:

private string _sampleString;
private int _sampleInt;
private long _sampleLong1, _sampleLong2, _sampleLong3;

Must not:

private string _sampleString;
private int _sampleInt;

  • Local variables must be clared as close as possible to its first use and must be in the same code block that use it.

Methods

  • A method must not exceed 100 lines. Methods with more than 100 lines usually decrease readability and thus maintainability.
  • Methods that relate to each others by any means should be grouped together.

Example:

#region Database Access Methods
#endregion Database Access Methods
#region Private Utility Methods
#endregion Private Utility Methods
#region Serialization Methods
#endregion Serialization Methods

  • Interface implementations must be grouped together.

Example:

public interface ISample
{
void SampleMethod();
}
public class SampleImplementation: ISample
{
#region ISample Members
void ISample.SampleMethod()
{
}
#endregion ISample Members
}

Indentation deep

  • All methods' indentation must not exceed a deep level of 3. Methods, whose indentation exceeds 3 in deep level, decrease readability, maintainability and also increase complexity.

Must not:

if (HasAccess)
{
for (int i = 0; i < COUNT; i++)
{
if (list[i].IsTrue)
{
switch (resourceType)
{
=> Code inside this block are too deep
}
}
}
}

Tips:
There are 2 methods for reducing the deep level of code block:

  • Reorganizing if statement

Original code:

public void SampleMethod(bool someCondition)
{
if (someCondition)
{
for (int i = 0; i < COUNT; i++)
{
}
}
}

Changed code:

public void SampleMethod(bool someCondition)
{
if (!someCondition)
return ;
for (int i = 0; i < COUNT; i++)
{
}
}

=> The indentation's deep level has been decreased by 1.

  • Creating private method

Original code:

public void SampleMethod(bool someCondition)
{
if (HasAccess)
{
for (int i = 0; i < COUNT; i++)
{
if (list[i].IsTrue)
{
foreach (int value in list[i].Values)
{
if (value > 0)
{
for (int j = 0; j < value; j++)
{
if (anotherCondition)
{
}
}
}
}
}
}
}
}

Changed code:

public void SampleMethod(bool someCondition)
{
if (HasAccess)
{
for (int i = 0; i < COUNT; i++)
{
if (list[i].IsTrue)
{
ProcessValues(list[i].Values);
}
}
}
}
private void ProcessValues(List<int> values)
{
foreach (int value in values)
{
if (value > 0)
{
for (int j = 0; j < value; j++)
{
if (anotherCondition)
{
}
}
}
}
}

=> The indentation's deep level is dreased more than 1

Attribute declaration

  • For elements that have more than one Attribute declaration, then each Attribute must be put on one line.

Must not:

[Serializable, STAThread, Obsolete("This class is obsolete. Use class Abc instead.")]
public class SampleClass

Must:

[Serializable]
[STAThread]
[Obsolete("This class is obsolete. Use class Abc instead.")]
public class SampleClass

Coding guidelines

Basic language usage

Access modifier

  • All access modifier must be explicitly given, except in interface's declaration where public is undertood by default.

Must not:

class SampleClass
{
int sampleInt;
void SampleMethod()
{
}
}

Variables and Types

  • If possible, initialize variables at declaration time.

Should:

private int primaryId = 0;
private string sampleString = string.Empty;
private List<int> sampleList = new List<int>();

  • Must use fully qualified name of types, declare the type by using statements. In case there are duplication in type's name, define aliases.

Must not:

ResourceCollectionPager pager = CatGlobe.Framework.Services.SessionManager.Current.DataModule.Get<ResourceCollectionPager>(Request["sessionid"]);

Must:

using CatGlobe.Framework.Services;
ResourceCollectionPager pager = SessionManager.Current.DataModule.Get<ResourceCollectionPager>(Request["sessionid"]);

Tips:
Always choose “using” over fully qualified name from Resolve menu of Visual Studio.
Resolve menu of VS2008

Example of using alias:

using Threading = System.Threading;
using Timers = System.Timers;
using Web = System.Web.UI;
namespaceCatGlobe.DataAccess
{
public class SampleClass
{
private Threading.Timer _threadTimer1;
private Timers.Timer _threadTimer2;
private Web.Timer _threadTimer3;
}
}

Constants and Literals

  • Never hardcoded strings that will be presented to end-users. Use Resoures class instead.

Must not:

<span>Username</span>

Must:

<span><%=Resources.Username %></span>

  • Try to use @ instead escape characters symbol

Should:

string filename = @"D:\test\test.xml";

Direct cast vs. as keyword

Following code block:

CustomClass a = src as CustomClass;

can be considered the same as the code block below:

if (src is CustomClass)
return (CustomClass)src;
else
return null;

Consequently, it is encouraged to use as keyword over directcasting, because it is neat and safer.

Exceptions handling

  • Catch least generic exception first

Must not:

try
{
using (FileStream fs = newFileStream(@"D:\test.xml")) { }
}
catch (Exception) { }
catch (IOException)
{
=>Unreachable code
}

  • Do not use exception for controlling flows, instead try to validate input parameter. Most of the time exceptions can be prevented by proper input validation.

Should not:

string input = "something";
try
{
DoWork(input);
}
catch (Exception e)
{
DoAlternateWork(input);
}

  • All exception must be re-thrown, the outest layer (usually GUI win-form or web-form) must responsible for handling the exception properly.

Must not:

try
{
DoWork();
}
catch (Exception e)
{
// do nothing
}

  • If not creating a wrapper exception, use “throw” instead of “throwe” to reserve the call-stack. “throw” statement's stack trace points to the code place that actually causes the error, while “throwe”'s stack trace points to the location of the “throwe” statement only.

Must not:

catch (IOException ioe)
{
Logger.LogError(ioe);
throw ioe; => Must be throw;
}

Correct:

catch (IOException ioe)
{
Logger.LogError(ioe);
throw new CustomeException("error", ioe);
}
catch (IOException ioe)
{
Logger.LogError(ioe);
throw;
}

Document revisions

Version No. Date Changed By Description
0.1 10.07.2008 Nguyen Trung Chinh Copy from http://blogs.msdn.com/brada/articles/361363.aspx
0.1 22.08.2008 Nguyen Trung Chinh Refine from original document, add more applicable rules
0.1 25.08.2008 Nguyen Trung Chinh Fix for 0.1 after reviews of Dennis and Thuan
0.2 08.10.2008 Nguyen Trung Chinh Add section 3.5 and 4
0.3 13.10.2008 Nguyen Trung Chinh Finish section 4
1.0 14.11.2008 Nguyen Trung Chinh Finalize version 1.0