Based on. NET project Code writing specification requirements book

Source: Internet
Author: User
Tags definition bool constant constant definition error code modifiers custom name
Specification | Project This article for the second half of the year for a project to write a brief code of writing specifications, not exhaustive, but still have reference value. But the code writing specification is more important to the team members of the project awareness of the improvement, according to this project so far, the implementation of this simple specification is not optimistic, the code still has a variety of genres style, this problem is the software project team management in the imperfect, this issue is not studied.

The first chapter of the subject naming norms
First, the external service naming code
1) Service project naming

All service project names begin with ESRV (note the case), and the fifth letter begins to be customized, but the fifth digit must be capitalized. For example, ESrvDemo1, where Demo1 is a custom name.



Second, the class member access rights specification
All class members have to set their access modifiers strictly according to the nature of the members ' use, and the modifiers have the following meanings:

Declared accessibility
Significance

Public
Access is unrestricted.

Protected
Access is limited to types that contain classes or derive from the containing class.

Internal
Access is limited to the current assembly.

protected internal
Access is limited to the current assembly or type derived from the containing class.

Private
Access is limited to the containing type.





Chapter II Code Writing specification
Code Annotation Specification
1). cs file Annotation

All. cs files must be annotated at the beginning of the file creation time, author, usage overview, etc.

The format is as follows:

//********************************************************

New Date: 2004.7.19

Author: XXX

Content Description: Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//********************************************************



2 Function Procedure Annotation

All function bodies are preceded with a comment, so the annotation is used. NET annotation specification, in the following format:

<summary>

Constructors

</summary>

<param name= "is_xxx1" > Sample Parameters 1</param>

<param name= "is_xxx2" > Sample Parameters 2</param>

Public Upgradethread (String is_xxx1, String is_xxx2)

{

...

}



3) constant Variable annotation

All constant variables, whether global or local, need to be annotated for everything that is critical to the code as a whole. The following example:

<summary>

The local save path to the backup file that the current thread points to

</summary>

public string storepath = "";



4) Code Modification Comment

When the developer maintains the previous program code, it needs to be at the beginning and end of the change, plus its own annotation information, in the following format:

BEGIN 2004-7-19 Jayson fixed the xxx problem

Slightly...

End 2004-7-19 Jayson



Code typesetting specification
1) Statement structure

In order to ensure the clarity of the sentence structure and the readability of the program, we should pay attention to the following problems when writing the software program:

L write only one statement on a single line and use spaces, blank lines, and transitions to ensure clear visuals.

L each nested function block, using a tab indent, curly braces must be placed on the next line of the conditional statement, in a single row, to make it easier to pair.

For example, there is a procedure as follows:
for (int i=0; i<10; i++) {Console.WriteLine ("xxxxx")}

Should be written as:

for (int i=0; i<10; i++)

{

Console.WriteLine ("xxxxx")

}











2 Code Writing format specification

L files must not exist without rules, such as 10 consecutive empty lines. Generally speaking, the null behavior between function and function is 2-3 lines;

L within the function body, a logically independent block of two functions can be properly blank, typically 1-2 lines.

L try to avoid exceeding the screen width of each line length and should not exceed 80 characters.

• Use public procedures or subroutines as much as possible instead of repeating functional code snippets.

L use parentheses to clearly express the order of arithmetic expressions and logical expressions. If the x=a*b/c*d is written as a x= (a*b/c) *d the reader may be prevented from being misunderstood as x= (a*b)/(C*D).

• Avoid overly complex conditional testing.

L Avoid excessive loop nesting and conditional nesting.

L A function should not exceed 200 lines. A file should avoid more than 2000 lines.

L Avoid using goto statements.

L Avoid using multiple assignment statements, such as x = y = Z;



Third, the definition of structural norms
1 naming rules (defined within the Itradedefine namespace):

L in capital letters

L TAG_XXXX with TAG Big Head, underline the name of the specific structure defined after

2) Example:

L Public struct Tag_allmessage

Iv. enumeration Type definition specification
1) Naming rules:

L in capital letters

L EU_XXXX in the European Union, followed by an underscore defining the type name

2) Example:

L Public enum Eu_message

Specification of constant definitions
1 The global use of constants (defined within the Itradedefine namespace)

L Example:

N Public const BOOL G_trans_false = FALSE;

L Constant Definition Specification

N Capital Letter Naming

N g_xxx_yyy G represents global, XXX identifies constant use, YYY identifies specific values



2 local use constants (defined in front of each class)

L Example:

n Public const int l_priority_lowest = 0

L Constant Definition Specification

N Capital Letter Naming

N l_xxx_yyy L represents a local, XXX identifies a constant purpose, YYY identifies a specific value



VI. specification of variable definitions
1 Variable definition principle

The basic principle of variable definition is: variable name = attribute + Type + Object Description + custom.

Each variable definition is defined as much as possible at the beginning of a function or process, avoiding irregular interspersed definitions in the code.



2) variable attribute name table

Property
corresponding identifier

Global variables
G_

Constant
C_

Class member variable
M_

Local variables
No attribute prefix





3 Variable type naming table

Type
corresponding identifier

Handle
H

Boolean type
B

Floating-point type
F

No sign
U

String
Sz

Digital type
I





4 Variable Type description table

Type
corresponding identifier

Class
Init

Temporary variable
Tmp

Destination Object
Dst

Source Object
Src

Window
Wnd





5) Example

Defines a global string-type custom variable: G_szdemo.

Specification of function naming
1 Avoid the use of "_" in the function name.

2 function of the same set of functions to define a function shorthand, as the prefix of the group function.

3) xxxyyyzzz XXX represents the function's prefix Yyy the function's action Zzz the object that identifies the function

4) Example: Delegategetbody ()



The return value specification of function out parameter entry parameter
1) function input and output parameters

The function join parameter begins with the prefix "IX", which is then performed according to the "type + object description + customization" Principle in the variable definition.

Example: String Isquepath into the parameter ref Itfparam otquebody the argument

2) function return value

Avoid using complex types such as structs

Use bool Type: This function only needs to get success or failure of return information when

Use int type: Error code is represented by a negative number, successfully returned 0



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.