C program development specification

xiaoxiao2021-03-06  49

Program Design Specification 1. Folder Naming Rules 1.1 folder named

1 Establish a corresponding folder according to the structure specified in the system design, establish a subfolder 2 folder according to need to be able to express its meaning, try to use English name, absolutely unable to use the Chinese characters 3 folder names must be used to write Letters (such as "/ eXample") 1.2 file naming

1 The name of the file should be as possible to express its meaning, try to use English name, absolutely can not use the Chinese characters 2 file names all using lowercase letters (ensuring platform compatibility) 3 file names generally adopted "xxx_yyy.ext" format, xxx (3-4 letters ) Represents classification, YYY (such as "/example/exp_edit.htm") 2. Program writing rules 2.1 variable naming

All variables must be able to reflect the role of variables, using the following naming rules: (1) Creating a true constant with a constant naming convention. This convention uses cases in which case mixed format, and "con" as a constant name. For example: conyownConstant

(2) Variable naming conventions For the purpose of easy-to-read and consistency, use the following variable naming convention in the VBScript code: type prefix example

Boolean BLN BLNFOUND

Byte byt bytrasterdata

Date (TIME) DTM DTMStart

Double DBL DBLTOLERANCE

Error Err erroternum

Integer Int IntQuantity

Long LNG LNGDISTANCE

Object Obj Objcurrent

SINGLE SNG SNGAVERAGE

String strsyname

(3) The variable scope prefix has a rapid distraction of the variable as the length of the Script code is increased. Add a single-character prefix in front of the type prefix to achieve this without causing the variable name too long. Scope prefix example

Process grade no dblvelocity

Script level s sblncalcinprogress

Monitor G GBLNCalcinProgress

⑷ Descriptive variable name and process name variable name or process name body should use case-to-write mix format, and describe its purpose as much as possible. In addition, the process name should begin with verb, such as initNameArray or Closedialog. For frequently used or longer names, standard abbreviations are recommended to keep the name within the appropriate length. Metades typically be more than 32 characters will become difficult to read. When using abbreviations, be sure to be consistent throughout Script.

Object Naming Convention, the following table lists object naming conventions (recommended) that may be used in VBScript: Object Type Prefix

Text box txt txtlastname

List LIN LINVERTICAL

Check box Chk ChkReadonly

Combination box, drop-down list box CBO CBOENGLISH

Label LBL LBLHELPMESSAGE

Command button cmd cmdexit

Frame fraraanguage

Image IMG IMGICON

Line LST LSTPOLICYCODES

Public dialog DLG DLGFILEOPEN

Horizontal scroll bar HSB HSBVOLUME

Vertical scroll bar vsb vsbrate

⑸ Code Note The beginning of all processes should have a brief comment describing its functions. When the use of parameters passing to the process is not obvious, or when the process requires the value of the value of the parameters, it should be explained. If the process changes the return value of the function and the variable (especially through the parameter reference), the return value should also be described at the beginning of the process.

The annotation of the process start section should contain the following segments. For related samples, see the "Format Code" section later.

The function of the segment title comment content destination (not a method of implementing the function). Suppose its state affects the list of external variables, controls, or other elements of this process. A list of effects effects on each external variable, control or other element. Enter the explanation of the parameters of each purpose. Each parameter should occupy a separate line and have its internal annotation. Returns the explanation of the return value. Keep in mind that each important variable declaration should have internal annotations, describe the use of variables. The variables, controls, and processes should be clearly named, which requires internal annotations only when explaining complex details. The beginning of Script should include an overview describing the Script, an object, a process, an algorithm, a dialog, and other systems from the base. It is useful to have a false code of the description of the algorithm. The formatting code should keep the screen space as much as possible, but still allow the logical structure and nested by code format. The following is a few suggestions: Standard nesting blocks should be indented into 4 spaces. Overview of the process Note Should be indented into 1 space. Overview The highest layer statement after comments should indent 4 spaces, and each layer is nesting into 4 spaces. E.g: '*********************************************** ********** 'Purpose: Returns the location where the user appears in the UserList array. 'Enter: struserlist (): The list of users found. 'Strtargetuser: The user name to find. 'Return: Strtargetuser's index when the StruserList array appears. 'If the target user is not found, return -1. 'Date: Designed by MS 2000/9/12' ************************************************** *******************

Function intFinduser (StruserList (), STRTARGETUSER DIM I 'loop counter. DIM BLNFOUND 'discovers the mark of the target. INTFINDUSER = -1 i = 0 'Initialization Cycle Counter. Do While i <= ubound (struserlist) and not blnfound if struserlist (i) = startagetuser dam set = true 'tag is set to true. The INTFINDUSER = I 'return value is set to a loop counter. End if i = i 1 'cycle counter plus 1. Loop end function

2.2 Common Library

1 All public function files are placed in the "/ include" directory, unified management, and make appropriate classification and adjustment 2 All public functions must write function, parameter definition, and return values ​​before the function, parameter definition, and return value, for example: 2.4 Comments

1 Note Try to use Chinese 2 2 Each program must have the following notes: Program name, program description, implementation, designer, design date 3 The program code section must have enough code snippet, express the writing of the program segment Intension and implementation principle 2.5 program structure

1 In the program code, there is enough fault tolerance. 2 Report programs and query programs should be flexible, try to provide a sufficient option to users 3 The program code structure must be clearly clear, use the air line segmentation 3. Interface design rules

1. Interface design is as beautiful, practical, unified 2. Interface design should try to refer to the idea of ​​the art 4. Test rules

1. After the program is written, the necessary tests should be performed. 2. Test cases To overwrite each functional module. The named rule is more famous naming rules to push Microsoft's "Hungary" method, the main idea of ​​this naming rule is "to add prefix in variables and function names to enhance people's understanding." For example, all character variables are prefixed in CH, and if the pointer variable is added, the prefix P is added. If a variable starts by the PPCH, it indicates a pointer to the character pointer. The biggest disadvantage of "Hungary" law is cumbersome, for example

INT I, J, K;

Float X, Y, Z;

If the "Hungary" naming rules are used, they should be written.

INT II, ​​IJ, IK; // Prefix i Represents INT Type

FLOAT FX, FY, FZ; // Prefix F Represents Float Type

Such a cumbersome procedure will make the most programmers can't stand it.

According to investigation, there is no name rule that allows all programmers to agree, and the programming textbooks generally do not specify naming rules. Naming rules are not "success or failure" for software products. We don't have much effort to present the best naming rules in the world, but should develop a naming rule that makes most project members, and Implementation in the project.

3.1 Community Rules This section The common rules discussed by most programmers shall be adopted by most programmers, and we should expand specific rules, such as 3.2.

l [Rules 3-1-1] The identifier should be intuitive and can be spent, and it is desirable to know that "decoding" is not required.

The identifier is preferably used in English words or its combination, which is easy to remember and read. Don't use Chinese Pinyin to name. The English words in the program generally don't be too complicated, and the words should be accurate. For example, don't write CurrentValue into NOWVALUE.

l [Rules 3-1-2] The length of the identifier should comply with the principle of "min-length".

A few decades ago, the old ANSI C specified that the name was not allowed to more than 6 characters. Today's C / C no longer restrictions. In general, long names can better express the meaning, so the function name, variable name, and class names are not blame for more than a dozen characters. So is the longer the name? Do not see! For example, the variable name MaxVal is easy to use than MaxValueuntiloverflow. The name of a single character is also useful, common as i, j, k, m, n, x, y, z, etc., which are usually used as partial variables within the function.

l [Rules 3-1-3] Naming rules should be consistent with the style of the operating system or development tool used.

For example, the identifier of the Windows application typically uses "case" mixing, such as addChild. The identifier of UNIX applications typically uses the "lowercase loopline" approach, such as add_child. Don't mix these two types of styles together.

l [Rules 3-1-4] Do not appear similar identifiers that only rely on case in cases.

E.g:

INT X, X; // Variable X and X easy confusion

Void foo (int x); // Function foo is easy to confuse with foo

Void foo (float x);

l [Rules 3-1-5] Do not appear on the identifier exactly the same local variables and global variables, although both the scope of the two do not have a grammatical error, but will misunderstand.

l [Rule 3-1-6] The name of the variable should use "noun" or "adjective noun".

E.g:

FLOAT VALUE;

Float oldValue;

Float newValue;

l [Rules 3-1-7] The name of the global function should use "verb" or "verb noun" (mobile phrase). The member function of the class should only use "verbs", and the noun omitted is the object itself.

E.g:

Drawbox (); // global function

Box-> DRAW (); // member function

l [Rules 3-1-8] Named the correct antisense word group named mutually exclusive variables or function of the opposite action.

For example: int minValue;

Int maxValue;

Int setValue (...);

Int getValue (...);

2 [Recommendation 3-1-1] Try to avoid digital numbers in the name, such as Value1, Value2, etc. unless the number is logically required. This is to prevent programmers from being lazy, refuse to name the brains, resulting in the meaningless name (because of the most expensive thing).

3.2 Simple Windows Application Naming Rules Author's reasonable simplification of the Hungary naming rules, the following naming rules are simple and easy to use, compare the development of Windows applications.

l [Rule 3-2-1] The class name and function name are combined with the word starting with uppercase letters.

E.g:

Class node; // class name

Class LeafNode; // Classification

Void Draw (void); // Function Name

Void setValue (int value); // function name

l [Rule 3-2-2] variables and parameters are combined with a word starting with lowercase letters.

E.g:

Bool flag;

Int drawMode;

l [Rules 3-2-3] Constants use uppercase letters and segment words with underscore.

E.g:

Const int max = 100;

Const int max_length = 100;

l [Rule 3-2-4] Static variable add prefix S_ (represents static).

E.g:

void init (...)

{

Static int s_initvalue; // static variable

...

}

l [Rule 3-2-5] If a global variable is not required, the global variable is prefixed G_ (represents global).

E.g:

INT g_howmanypeople; // global variable

INT g_howmuchmoney; // global variable

l [Rule 3-2-6] The data member of the class is prefix M_ (represents member) so that the data member and the member function are the same name.

E.g:

Void Object :: setValue (int width, int hotht)

{

m_width = width;

m_height = height;

}

l [Rules 3-2-7] In order to prevent some identifiers in a single software library and other software libraries, it can be used to reflect the prefix of the software properties for various identifiers. For example, all library functions of the 3D graphic standard OpenGL are starting with GL, all constants (or macro definitions) start with GL.

Author Blog:

http://blog.9cbs.net/onlytiancai/

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

New Post(0)