Code writing specification ASP.NET (C #)

xiaoxiao2021-03-06  27

I wrote it for a while, everyone exchanges. Reprinted please indicate: http://blog.9cbs.net/yu_nan88

Code writing specification (C #)

V1.2

November 4, 2004

category

File name: coding specification version number: V1.2 Version Date: 2004-11-04 Author: Nick Date: 2004-11-04

table of Contents

1 purpose. 4

2 range. 4

3 Notes Specification. 4

3.1 Overview. 4

3.2 Self-built code file comments. 4

3.3 Module (class) Notes. 5

3.4 class attribute comments. 5

3.5 Method Note. 5

3.6 Interpretation. 6

4 named overall rules. 6

5 Name specification. 6

5.1 Variable (variable) named. 6

5.2 constant naming. 8

5.3 class (Class) named. 8

5.4 Interface (Interface) Named. 9

5.5 Method Named. 9

5.6 Name Space (Namespace) Named. 9

6 coding rules. 9

6.1 Error inspection rules. 9

6.2 Brand rules. 9

6.3 indentation rules. 9

6.4 Brand rules. 10

6.5 IF THEN ELSE Rule. 10

6.6 Comparison rules. 10

6.7 Case rules. 11

6.8 alignment rules. 11

6.9 Single-speech rules. 11

6.10 Single function rules. 11

6.11 Simple functional rules. 11

6.12 Clear conditional rules. 11

6.13 Select FALSE Rules. 11

6.14 Independent Assignment Rules. 12

6.15 Define constant rules. 12

6.16 Modularization rules. 12

6.17 AC rules. 12

7 Programming Guidelines. 12

7.1 Variables. 12

7.2 Database Operation. 12

7.3 Objects use. 13

7.4 Module Design Principles. 13

7.5 Structured requirements. 13

7.6 Function Return Value Principle. 13

8 Code Pack Specification. 14

8.1 version number of the code package. 14

8.2 The logo of the code package. 14

9 Code Control. 15

9.1 Establishment of the Code Base / Directory. 15

9.2 Code Archive. 15

10 Enter the control verification rule. 15

10.1 Landing Control. 15

10.2 Data entry control. 15

Annex 1: Data type abbreviation table. 16

Annex 2: Server Control Find Writer. 16

1. Purpose

In order to unify the design of the company's software development, the programming specification for code writing and the specific development work, ensuring the consistency of the code, which is easy to communicate and maintenance, and specialize this specification.

2. area

This specification applies to all staff of the development group, acting on code preparation stages and post-maintenance stages developed by software project development.

3 Notes Specification

3.1 Overview

a) Note Requires the punctuation of English and English.

b) In the annotation, the complete name of the object should be indicated, but the code should be avoided too detailed description of the code.

c) The maximum length of each line is 100 characters.

d) Separate the comment with the comment separator with a space.

e) Do not allow an extraction box to the comment.

f) Writing a comment while encoding.

g) The important variable must have a comment.

h) Variable annotations and variables in the same line, all comments must be aligned, separated from the variables to at least two "TAB" keys.

Such as: int m_ilevel, m_icount; // m_ilevel .... Tree Level // m_icount .... Count of Tree Items

String m_strsql; // SQL

i) Typical algorithms must be annotated.

j) The uplink must be written in the loop and logical branch.

K) The annotation of the block or statement in the block or statement

l) Before the code is delivered, temporary or unrelated comments must be deleted.

m) For ease of reading code, each line code should be less than 100 characters.

3.2 Self-built Code Document Notes

For your own code files (such as functions, scripts), starting with the file, generally preparing the following comments:

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

FileName:

Copyright (C) 2004-XXXX ******** Company Technology Development Department

Writer:

Create Date:

Rewriter:

Rewrite Date:

Impact:

Main Content (Function Name, Parameters, Returns)

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

3.3 Module (class) Note

The module must be written in the following form:

///

/// Module ID:

/// defiction:

/// Author: Author Chinese name

/// Create Date:

///

If the module only changes some small number of code modifications, you must add the following notes each time you modified:

/// REWRITER: REWRITE DATE: Start1:

/ * Original code content * /

/// end1:

Comment the original code content, then add a new code to use the following comments:

/// added by: add date: Start2:

New code content

/// end2:

If the module input / output parameter or function structure has a large modification, each modification must add the following notes:

///

/// log ID:

/// defiction:

/// Writer: Modify Chinese name

/// REWRITE DATE:

///

3.4 class attribute comments

Attributes in the class must be written in the following format:

///

///

///

3.5 Method Note

You must write a comment below ///

in the following format declaration.

/// defiction:

///

///

Public Class Hello

{

PRIVATE STRING M_STRNAME;

Private datetime m_dtdate;

}

Ø The variable corresponding to the attribute of the class, using the "M _" type abbreviated prefix with the attribute name

Public Class Hello

{

PRIVATE STRING M_STRNAME;

Public String Name

{

get

{

Return M_StrName;

}

}

}

Ø Process variable use type abbreviation prefix

Public Class Hello

{

Void Say ()

{

String strsayword;

}

}

Ø Parameters of the process use "P _" type abbreviation as a prefix (where P is "parameter" abbreviation)

Public Class Hello

{

Void Say (String p_strsayword)

{

}

}

Supplementary description:

Named an Exception variable in the abnormal capture process, unified named Exp for no conflict;

If there is a conflict, you can use the "Exp" logo name, such as: expsql.

Try

{

// Your Code

Try

{

// Code

}

Catch (Exception Exp)

{

// Your Code

}

}

Catch (Exception EXPSQL)

{

// Your Code

}

Supplement: If you do not need to be processed, you do not need to define an Exception instance.

example:

Try

{

// Your Code

}

Catch (Exception Exp)

{

}

Ø 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.

Ø The meaningful name is still used even if there is a short variable that may only appear in several code lines. Use a single-letter variable name only for short cyclic indexes, such as I or J.

Ø Use complementaries in the variable name, such as Min / Max, Begin / End and Open / Close.

Ø 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 <= num_days_in_week; i ) to facilitate maintenance and understanding.

b) Control naming

Control Name = Web Control Abblast Prefix "_" Name

Such as: DataGrid DG_UserList

5.2 constant naming

Constant numbers should also have some meaning, format is 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.

5.3 class (Class) named

a) The name should be able to identify the characteristics of things.

b) Name as much as possible without abbreviations, unless it is well known.

c) The name can be composed of two or three words, but usually should not be more than three.

d) In the name, all words are the first letter. For example, Issuperuser, containing ID, all uppercase, such as CustomerID.

e) Name the class or noun phrase.

f) less abbreviation.

g) Do not use underscore characters (_).

Example: Public Class FileStream

Public Class Button

Public Class String

5.4 Interface (Interface) Name

As the class naming specification, the only difference is that the interface plus "I" pre-embedded precedent before the name:

Interface idbcommand;

Interface ibutton;

5.5 Method Named

The same name naming specification.

5.6 Name Space (Namespace) Named

The same name naming specification.

6 coding rules

6.1 Error Check Rules

a) Programming to consider various implementations of functions, and handle all processes as much as possible.

b) Check the error message for all system calls unless you want to ignore the error.

c) divide the function two categories: one class is independent of the display of the screen, the other is related to the display of the screen. For functions independent of the screen display, the function reports an error by the return value. For functions related to the screen display, the function is responsible for issuing a warning to the user and performs an error handling.

d) Error handling code is typically placed at the end of the function.

e) For universal error processing, a universal error handler can create common universal errors.

6.2 Rules of Brackets

Place the braces in the same column below the keyword, for example:

IF ($ condition) While ($ condition)

{{

...

}

6.3 indentation rules

Use a "Tab" to indent each level. E.g:

Function func ()

{

IF (Something Bad)

{

IF (ANOTHER Thing Bad)

{

While (more input)

{

}

}

}

}

6.4 Brand rules

a) Do not close the small brackets and keywords (if, while, etc.) to separate them with spaces.

b) Do not close the parentheses and function names.

c) Do not use parentheses in the return return statement unless necessary. Because the keyword is not a function, if the parentheses close to the function name and keyword, both are easy to be considered one.

6.5 IF THEN ELSE Rules

If you use it to the else if statement, it usually has an else block for processing unprocessed. If you can put a record information comment at else, even in Else doesn't have any action. The format is:

IF (Condition 1) // Comment

{

}

ELSE IF (Condition 2) // Note

{

}

ELSE // Note

{

}

Note: IF and cycles of nesting up to 4 layers

6.6 comparison rules

Always put the constant amount on the left side of the equal number / do not equal. One reason is that if you are leaking a equal sign in the equation, the syntax checkter will report an error. The second reason is that you can find a value immediately instead of finding it at the end of your expression. E.g:

IF (6 == $ ErrorNum) ...

6.7 Case rules

Default Case should always exist. If you are not allowed, you should guarantee that if you arrive, you will trigger an error. Case's selection criteria preferably use int or String type.

6.8 alignment rules

The decimation and initialization of variables should be aligned. E.g:

Int m_icount;

INT I, J;

Float m_fincome, m_fpay;

m_icount = 0;

i = 1;

m_fincome = 0.3;

6.9 Single-speech rules Unless these statements have very close contact, only one statement is written in each row.

6.10 single function rule

In principle, a program unit (function, routine, method) completes only one feature.

6.11 Simple functional rules

In principle, the code of a program unit should be limited to one page (25 ~ 30 rows).

6.12 Clear Conditional Rules

Do not test the non-zero value by default. For example: use "if (0! = F ())" without "if (f ())".

6.13 Select FALSE Rule

Most functions returns values ​​such as false, 0 or no, but the return value is not fixed when the correct value is correct (can not be represented by a fixed TRUE, 1 or YES), so it should be used to detect a Boolean value. Inequalities such as 0, NO are replaced. For example: use "if (false! = F ())" without "if (true == f ())".

6.14 Independent Assignment Rules

The embedded assignment is not conducive to the understanding of the procedure, and it may be repeatedly unique side effects, and the independent assignment statement should be prepared. For example: use "A = B C; E = A D;" without "e = (a = b c) D".

6.15 Define constant rules

For constants (especially numbers) referenced in the code, define should be a capital name, reference name in the code without direct reference.

6.16 Modularization Rule

A function, if you repeat it over and more, you should consider modularity, write it into a general function. And publish to the team members. At the same time, you should use other people's ready-made modules.

6.17 exchange rules

Sharing the work of others, providing others' work results.

In the specific task development, if there is any other coding rule, it is clearly defined in the corresponding software development plan.

7 Programming Guidelines

7.1 variable

a) The global variable is not allowed.

b) A variable can only have one use; the use of variables must be consistent with the name of the variable.

c) All variables must be defined in front of the class and functions and are classified.

7.2 Database Operation

a) When you look for database tables or views, you can only take out those fields that do need.

b) Use no associated subqueries instead of using associated subqueries.

c) clearly understand the column name without using the sequence number of the column.

d) Use the transaction to ensure the integrity of the data.

7.3 object use

a) Create an object as much as possible and release it as early as possible.

7.4 Module Design Principle

a) The public function and class is not allowed to define the public.

b) The function function is single and does not allow a function to implement two and more than two functions.

c) The global variable cannot be used inside the function. To use global variables, it should be converted to a local variable.

d) There is only a relationship between the function and the function, and there is no cross-relationship. That is, there is only one directional call and called called, and there is no two-way call and called.

7.5 Structured requirements

a) It is forbidden to appear two equivalent branches.

For example: IF (a == 2)

//

ELSE IF (a == 3)

//

Else IF (a == 2)

//

Else

//

b) Avoid using a GOTO statement

c) Use the IF statement to emphasize only one of the two groups of statements. Do Else Goto and else return.

d) Multi-channel branch e) to avoid multiple exits from cycles.

f) There is only one exit.

g) Do not use the condition assignment statement.

h) Avoid unnecessary branches.

i) Do not easily use conditions branch to replace logical expressions

7.6 Function Return Value Principle

1) Function return value

Avoid complex types such as structures

Using BOOL Type: This function only needs to be successful or failed to return information

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

8 code package specification

In this project, each task should be packaged and archived after completing a stable version.

8.1 code number of the code package

In the project, the version number of the code package consists of two numbers spaced apart from the circle. The first number indicates the issuance number, and the second number represents the modification number of the version. The specific usage is as follows:

1) When the code package first version, the version number is V1.00;

2) When the code package is modified or bug correction, the issuance number is unchanged, and the number of modifications is increased by 1. For example, the primary version of the code is a first revision, and the version number is V1.01;

3) When the code package increases some of the function, the issuance number is unchanged, the number of modifications is unchanged, and the modification number is 1, for example, add some functions on the basis of V1.12, then the new version number is V1.20 ;

4) When the code package has important modifications or local amendments, the code is incremented by 1. For example, on the basis of V1.15, a comprehensive revision is made, and the new version number is V2.00.

8.2 Code Package Identification

The code packages generated by this project have unique, specific encodings, which are as follows:

S-project identification - code package type - version number / serial number

among them:

1) S: The logo of this project, indicating that the project is "xxxx".

2) Item ID: Sign up of this project, this identifier applies to documents of the entire project.

3) Code Pack Type: Near the two alphabetic codes below.

4) Version number: The version number of this code package.

5) Sequence number: four digit coding, indicating the total number of the code package in the project code library.

E.g:

The compressed code package of RAR source code under Windows is named: S-XXXX-WS-V1.02 / 0001

Project code package classification table

Type Code Note RAR Pack (Windows) Source Code File WS Source Code File Compile File WB Compile Packet Installation File WI Installation File Package Code Code Installation File WA Source Code and Installation File RPM Pack (Linux) Source RS Source In RPM Binary code RE EXECUTIONIN RPM tar.gz package (Linux) source TS Source in tar.gz binary code TE EXECUTION IN TAR.GZ source code binary code Ta Source & Excution in tar.gz

The identity list of all code packs in the project will be specifically defined in the Project Development Plan.

9 code control

9.1 Creation of the Code Base / Directory

The project leader establishes the document library directory of the project in VSS, which is the "Software" directory for quick query.

9.2 Code Archive

After completing a stable version, the project person in charge should be packaged, stored in the "Software" directory of the project in VSS, and assign a unique name based on the naming specification of the code package. 10 input control verification rules

10.1 Landing Control

User login ID and login password, to qualify the input length range, you must check the entered legitimacy.

10.2 Data Entry Control

a) TextBox input

1. Want to keep the user input and the length of the database receipt

2, you must enter the legitimacy check

Such as: e_mail format xxx@xxx.xxx ...

Phone format 020-12345678

(020) 12345678

Zip code is six

b) Except for Checkbox, Radiobutton, prohibiting other editing controls within DataGrid to add editing data

Attachment 1: Data type abbreviation table

Data type Abbreviation STRING STIT I Char SBYTE SB BYTE BT UINT UI Long L Ulong UL Float F Double D Bool B Decimal Dec

Attachment 2: Server Control Find Writing Sheet

A, web control

web controls initials AdRotator art Button cmd Calendar cd CheckBox chk CheckBoxList chkl CompareValidator cpv CustomValidator ctv DataGrid dg DataList dl DropDownList ddl HyperLink hl Image img ImageButton Icmd Label lab LinkButton lcmd ListBox lst Panel pl PlaceHolder ph RadioButton rb RadioButtonList rbl RangeValidator rv RegularExpressionValidator rev Repeater rp RequiredfieldValidator RFV Table Tb Tablecell Tc Tablesummary VS XML XML

B, HTML control

html controls initials HtmlAnchor hah HtmlButton hcmd HtmlForm hform HtmlGenericControl hgc HtmlImage himg HtmlInputButton (button) htxt HtmlInputButton (reset) hrcmd HtmlInputButton (submitted) hccmd HtmlInputCheckBox hick HtmlInputFile hifile HtmlInputHidden hihidden HtmlInputImage hiimg HtmlInputRadioButton hirb HtmlInputText (password) hpwd HtmlInputText (text) hitxt Htmlselect HSLT HTMLTable HTAB HTMLTablecell HTC HTMLTableRow Htr HTMLTextArea HTXTA

转载请注明原文地址:https://www.9cbs.com/read-65202.html

New Post(0)