One of the continued, the chickshole then translated the second chapter of the Idesign coding specification.
2 Coding conventions Coding practices
1. Avoid multiple classes in one file. Avoid Putting Multiple Classes in a Single File. 2. A file should only provide types of namespaces. Avoid having multiple namespaces in the same file. A Single File Should Only Namespace. Avoid Having Multiple Namespaces in The Same File. 3. Avoid the file length of more than 500 rows (except for the code automatically generated). Avoid Files With More Than 500 Lines (Excluding Machine-Generated Code). 4. Avoiding the method to define more than 25 lines. Avoid Methods with More Than 25 Lines. 5. Avoid more than 5 parameters. Use structures to pass multiple parameters. Avoid Methods with More Than 5 Arguments. Use Structures for Passing Multiple Arguments. 6. Each line should not exceed 80 characters. Lines Should Not Exceed 80 Characters. 7. Do not edit any machine generated by any machine. DO NOT MANUALLY Edit Any Machine Generated Code. A) Modify the code generated by the machine to modify the code format and style to meet this coding standard. If MODIFY AND STYLE TO MATCH THIS Coding Standard. B) use the Partial class as much as possible to decompose some parts that require maintenance. Use Partial Classes WHENEVER POSIBLE TO FACTOR OUT The Maintained Portions. 8. Avoid comments on apparent content. Avoid Comments That Explain The Obvious. A) The code should be self-explanatory. A good code consisting of multi-readability variables and methods should not be required. Code Should Be Self Explanatory. Good Code with Readable Variable and Method Names Should Not Require Comments. 9. Only for the premise of the operation, the intrinsic algorithm and other write documents. Document Only Operational Assumptions, Algorithm Insights and So on. 10. Avoid the method level document. Avoid Method-Level Documentation. A) uses a large number of external documents to the API document. Use Extensive External Documentation for API Documentation. B) Method CAUTION As a prompt to other developers. Use method tips for other development. 11. Never have a hardcore value, but always declare a constant. Never Hard-Code a Numeric Value, Always Declare a constant instead. 12. Use a const modifier only for values that are constant, such as one week. Use the constant the on Nature Constants Such as the number of days of week. 13. Avoid using a const modifier for read-only variables.
In this case, a Readonly modifier is used. Avoid using const on readonly variables For that, use the readonly directive public class MyClass {public readonly int Number; public MyClass (int someValue) {Number = someValue;} public const int DaysInWeek = 7;}.. 14. Any Assume that uses ASSERT. Assert Every Assumption. A) Average, there is a line in every 5 lines. On Average, Every Fifth Line Is An assert; use system.diagnostics; object getObject () {Object obj = getObject (); debug.assert (Obj! = Null); 15. Each line of code should pass through a white box test. Every Line Of Code Should Be Walked THROUGH IN A 搘 Hite Box? Testing Manner. 16. Capture only an exception that has been explicitly processed. Only Catch Exceptions for Which You Have Explicit Handling. 17. In throwing an exception's Catch statement, the initial exception is always thrown to maintain an initial incorrect stack position. In a catch statement that throws an exception, always throw the original exception to maintain stack location of original error catch (Exception exception) {MessageBox.Show (exception.Message); throw; // Same as throw exception;}. 18. Avoid The return value of the error code is used as the method. 19. Avoid defining a custom anomaly class. Avoid Defining Custom Exception Classes. 20. Defines Custom Exception: When Defining Custom Exceptions: a) Inherited Derive The Custom Exception from ApplicationException. B) Provides custom serialization. Provide Custom Serialization. 21. Avoid having multiple main () methods in one program. Avoid Multiple Main () Methods In a Single assembly. 22. Only the most needed type is labeled as public, and other labeled INTERNALs. Make Only The MOST NECESSARY TYPES PUBLIC, MARK OTHERS AS INTERNAL. 23. Avoid using Friend assemblies, because this increases the coupling of the program.
Avoid Friend Assemblies, as it increas Inter-assembly coupling. 24. Avoid using code dependent on assemblies run from a specific location. Avoid Code That Relies on an assembly running from a particular location. 25. Minimize the code of the application set (client EXE assembly). Use class libraries instead of the business logic layer code. Minimize Code In Application Assemblies (Exe Client AssemBlies). Use Class Libraries Instead to Contain Business Logic. 26. Avoid providing a clear value for enumeration. Avoid Providing Explicit Values for Enums. // Correct Public Enum Color {Red, Green, Blue} // Avoid Public Enum Color {Red = 1, Green = 2, Blue = 3} 27. Avoid the specified type of enumeration. Avoid Specifying a type for an enum. // Avoid Public Enum Color: long {red, green, blue} 28. If statement is always using parentheses, even if it contains a statement. ALWAYS USE A CURLY BRACE Scope in AN IF IT CONDitions A Single Statement. 29. Avoid use?: Conditional operator. Avoid Using The Trinary Conditional Operator. 30. Avoid calling a function in a Boolean condition statement. Assign a local variable and check their values. Avoid Function Calls in Boolean Conditional Statements. Assign INTO LOCAL VARIABLES AND CHECK INTO LOCAL VARIABLES AND CHECK IN THEM: BOOL ISEVERYTHINGOK () {...} // Avoid: // Avoid: IF (ISEVERYTHINGOK ()) {...} // adopt: / / INSTEAD: BOOL OK = ISEVERYTHINGOK (); if (ok) {...} 31. Always use an array starting from 0. Always use zero-based arrays. 32. Always use a FOR cycle to explicitly initialize an array of reference types. Always explicitly initialize an array of reference types using a for loop public class MyClass {} MyClass [] array = new MyClass [100];. For (int index = 0; index Do Not Provide Public Or Protected Member Variables. Uses INSTEAD.