Editor: KKDING
Japanese issue: 2003-12-22
Current version: v 0.5
Version number Author Date Approval Date Sign Remarks 0.5kkding2003-12-22C
Note: C
-create;
M
- modification; d
- Delete; A
-Add to
table of Contents
1 purpose .... 3
2 range .... 3
3 specification content .... 3
3.1 file specification ... 3
3.1.1 file named ... 3
3.1.2 File content format ... 3
3.2 Code Format ... 4
3.3 Notes (Comment) Specification ... 5
3.3.1 Module (class) Note Specification ... 5
3.3.2 Class Attribute Notes Specification ... 6
3.3.3 Method Note Specification ... 6
3.3.4 Code Interpretation Specification ... 6
3.4 Variable (variable) naming norm ... 6
3.4.1 Variable Naming Rules in Program File (* .cs) ... 6
3.4.2 Control Naming Rules ... 8
3.4.3 Constant naming norm ... 9
3.4.4 Class (Class) Name Specification ... 9
3.4.5 Interface (Interface) naming norm ... 10
3.4.6 Method (Method) naming norm ... 10
3.4.7 Namepace (Namespace) Named Specification ... 10
4 implementation recommendations .... 10
1. Purpose
In order to ensure that the procedures prepared by the company are in line with the same specifications, the program coding specifications established by the consistency and unity are guaranteed.
The coding specification is especially important for programmers, and there are several reasons:
- A software life cycle, 80% of the cost is maintenance
- There is almost no software, which is maintained by the initial developers in the entire life cycle.
- The coding specification can improve the readability of the software, allowing programmers to completely understand new code as soon as possible.
- If you release the source code as a product, you need to make it very well packaged and clear, as you have built any other product
In order to implement specifications, each software developer must consistently comply with the coding specification. everyone.
2. area
Suitable for software development work based on C # .NET platforms.
3 specification content
3.1 File Specification
3.1.1 Document Name
The same name is the same name
3.1.2 File content format
Beginning notes
Quote
Namespaces
Species
Variables (proxy events): Use #Region variables ......... # EndRegion includes
Properties: Use #Region properties ......... # endregion includes
structure:
Method (Implementation): Use #Region method ......... # endRegion includes
3.2 Code Format
u All indentation is 4 spaces, in space instead of TAB. Check "Insert Space (
P) "
u Vertical to left parentheses and right brackets in the code.
IF (x == 0)
{
Response.write ("The user number must be entered!");
}
Not allowed to:
IF (x == 0) {
Response.write ("The user number must be entered!");
}
or:
IF (x == 0) {response.write ("The user number must be entered!");
u In order to prevent the source code editor from being switched when reading the code, each line code or comment must not exceed a display frequency at 1024 * 800. When a line is divided into several lines, the series operator is placed The end of each row is not starting, clearly indicating that there is no line behind it is incomplete.
u The statement placed on each line avoids more than one.
u User space before and after most operators, do not change the code's intent to make the code easy to read.
example:
INT j = i k;
Not writing
INT j = i k;
u Distribute large complex code sections into modules that are easily understood.
u When writing SQL statements, use all uppercase for keywords, use case-write mixing for database elements (such as tables, columns, and views).
u Place each primary SQL clause on a different line, which is easier to read and edit statements, for example: select firstname, lastname
From customer
Where stat = 'wa'
3.3 Notes (Comment) Specification
Note specification includes: module (class) annotation specification, class properties, method comment specification, inter-code interpretation
3.3.1 Module (class) Note Specification
The module must be written in the following form:
///
// / Define a certain type of method
/// summary>
///
///
///
If the module has a modification, you must add the following notes each time you modified:
///
3.3.2 Class attribute annotation specification
Attributes in the class must be written in the following format:
///
/// attribute description
/// summary>
3.3.3 Method Note Specification
Notes must be written in the following format before declaration of the class
///
/// Description:
/// summary>
///
Public Class Hello
{
Void Say (String
p_sayword)
{
}
}
Supplementary description:
Named an Exception variable in the abnormal capture process, in the case where there is no conflict, uniformly name E;
If there is a conflict, you can repeat E, such as: EE.
Try
{
// Your Code
Try
{
// Code
}
Catch (Exception)
EE)
{
// Your Code
}
}
Catch (Exception)
e)
{
// Your Code
}
Supplement: If you do not need to make any processing, you don't need to define an Exception instance.
example:
Try
{
// Your Code
}
Catch (Exception)
{
}
5. In view of the fact that most names are constructed by connecting several words, use case-write mixed formats to simplify their reading. The first letter of each word is capitalized.
6. The meaningful name is still used even for variables that may only appear in a few code lines. Use a single-letter variable name only for short cyclic indexes, such as I or J.
7. Using complementaries in the variable name, such as MIN / MAX, Begin / End, and Open / Close.
8. Do not use primary numbers or primary strings, such as For (i = 1, i <7; i ). But use naming constants, such as for (i = 1, i 3.4.2 Control Naming Rules Control naming = Web control abbreviated prefix "_" variable name Control Abbreviation LabellblTextBoxtxtXtCheckBoxChkButtoncmdListBoxlstdropdownListDrp, etc. 3.4.3 Constant Naming Specification Constant numbers should also have certain significance, format NOUN or Noun_verb. The constant name is uppercase, and the word is separated by underline. example: Private const bool web_enablepagecache_default = true; Private const INT Web_pagecacheexpiresinseconds_default = 3600; Private const bool_eb_enablessl_default = false; Note: The variable name and constant name can contain 255 characters, but the name of more than 25 to 30 characters is relatively awkward. In addition, you should take a name that has the actual meaning, clearly express variables or constants, 25 or 30 characters should be sufficient. 3.4.4 Class (Class) Name Specification 1. The name should be able to identify the characteristics of things. 2. The name is trying to use abbreviations, unless it is well known. 3. The name can be composed of two or three words, but usually should not be more than three. 4. In the name, all words first letters are capitalized, and abbreviations are capitalized. For example, Issuperuser, containing ID, all uppercase, such as CustomerID. 5. Name the class or noun phrase. 6. Less use of abbreviations. 7. Do not use underscore characters (_). example: Public Class FileStream Public Class Button Public Class String 3.4.5 Interface Naming Specification The same is the same as the class naming specification, the only difference is that the interface plus "i" prefix before the name. example: Interface idbcommand; Interface ibutton; 3.4.6 Method (Method) naming specification The same name naming specification. Another: The method starts trying to use the E-article. Equation with: getMoney, SetMoney 3.4.7 Namespace (Namespace) Naming Specification The same name naming specification. 4 implementation recommendations l First "Topic" training for the coding person, let them master this coding rule. l System designers, codents, testers can better advice, modify "C # coding specifications" appropriately l The modification of this document is modified to change, change the version number.