Frog Frog Recommended: C Procedures Development Specification.doc

xiaoxiao2021-03-06  60

Program design specification

1. Naming rules for folders and files

1.1 folder naming

1 Establish a corresponding folder based on the structure specified in the system design, establish a subfolder as needed

2 The name of the folder should be as expected to express its meaning, try to use English name, absolutely unable to Chinese characters

3 folder name must be used to use lowercase letters (such as "/ example")

1.2 file name

1 The name of the file should be as best as possible, try to use English name, absolutely can't happen

2 file names all use lowercase letters (ensure platform compatibility)

3 File names generally use the "xxx_yyy.ext" format, XXX (3-4 letters) indicate classification, YYY (alphabet self-qualified) means operation (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) constant naming conventions

Create a true constant with a const statement. This convention uses cases in which case mixed format, and "con" as a constant name. E.g:

ConyownConstant

(2) Variable naming conventions

For easy reading and consistency, use the following variable naming conventions in the VBScript code:

Types of

Prefix

Example

Boolean

BLN

BLNFound

Byte

BYT

Bytrasterdata

Date (Time)

DTM

DTMSTART

Double

DBL

DBLTolerance

Error

Err

ErrorDernum

Integer

int

IntQuantity

Long

LNG

LNGDISTANCE

Object

Obj

Objcurrent

Single

SNG

Sngaverage

String

Str

Strfirstname

(3) variable scope prefix

As the length of the Script code is increased, it is necessary to quickly distinguish the scope of the variable. 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

Full-scale

G

GblncalcinProgress

⑷ Descriptive variable name and process name

The subject of the variable name or process name should use the case in cases, and the purpose is intended to be integrated 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 the object naming conventions (recommended) that may be used in VBScript:

Object type

Prefix

Example

Text box

TXT

TXTLASTNAME

List box

lin

linVertical

Check box

chk

ChkReadonly

Combo Box,

Drop-down list box

CBO

Cboenglish

label

LBL

lblhelpMessage

Command button

cmd

cmdexit

frame

FRA

Fralanduage

image

IMG

IMGICON

straight line

LST

LstpolicycoDes

Public dialog

DLG

Dlgfileopen

Horizontal scroll bar

HSB

HSbvolume

Vertical scroll bar

VSB

vsbrate

⑸ Code Notes

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.

Section title comment

The function of the destination process (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.

Remember the following points:

Each important variable declaration should have internal annotations and 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.

Formatting code

The screen space should be reserved as much as possible, but the logical structure and nested are still allowed. Here is a few tips:

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 will appear 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 'cycle counter.

DIM BLNFOUND 'discovers the mark of the target.

INTFINDUSER = -1

i = 0 'Initializing the loop counter.

Do While i <= ubound (struserlist) and not blnfound

IF struserlist (i) = startergens

BLNFOUND = True 'marks set to True.

The INTFINDUSER = I 'return value is set to a loop counter.

END IF

i = i 1 'circular 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 categories and adjustments

2 All public functions must write function functions, parameter definitions, and return values ​​before the function, parameter definition, and return value, for example:

2.4 Notes

1 Note Try to use Chinese as much as possible

2 Each program must have the following notes:

Program name, program description, implementation, designer, design date

3 The program code section must have enough information about the code snippet, express the written intent and implementation principle of the program fragment.

2.5 program structure

1 There is enough fault tolerant handling function in the program code

2 Reporting Programs and Query Programs should be flexible, try to provide users with sufficient selection 3 The program code structure must be clear, properly use the blank segmentation

3. Interface design rules

1. Interface design is as beautiful, practical, unified

2. Interface design should try to refer to the advice 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.

Naming rule

More famous naming rules When pushing 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

The commonal rules discussed in this section are adopted by most programmers, and we should expand specific rules, such as 3.2, under the premise of following these common rules.

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.

E.g:

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

The author has reasonably simplified the "Hungary" naming rules, and 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.

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

New Post(0)