VC programming specification

xiaoxiao2021-04-10  244

VC programming specification

Author: wl3000wlnew

basic requirements

1.1 Program structure is analyzed, simple and easy to understand, the number of lines of individual functions must not exceed 100 lines. 1.2 What is going to do, it is simple, directly when it is straight, and the code is streamlined, and the garbage program is avoided. 1.3 Try to use the standard library function and public functions. 1.4 Do not define global variables at will, try to use local variables. 1.5 Use parentheses to avoid amphibia.

2. Readability requirements 2.1 readability first, efficiency second. 2.2 Hold the comment is exactly the same as the code. 2.3 Each source file has a file header, indicating that the specification is specified. 2.4 Each function has a function head description, indicating that the specification is specified. 2.5 Main variables (structures, joints, class or objects) are defined or referenced, the comments can reflect their meaning. 2.7 Constant Definition (Define) has a corresponding description. 2.8 Each phase of the process has a related note instructions. 2.9 There is a comment before the typical algorithm. 2.10 Using the logical structure of the display program, the indentation volume is consistent, and the Tab is 6 bytes. 2.11 Circulation, the branch level should not exceed five layers. 2.12 Note You can be in the same row with the statement, or you can go up. 2.13 Blank Characters is also a special annotation. 2.14 At a glance, the statement does not comment. 2.15 The scope of the annotation can be: definition, reference, conditional branch, and a piece of code. 2.16 Note (not including the program head and function header) should account for 1/5 to 1/3 of the total number of lines.

3. Structured requirements

3.1 Prohibition of two equivalent branches. 3.2 Prohibiting the goto statement. 3.3 Use the IF statement to emphasize only one of the two groups of statements. Do Else Goto and else return. 3.4 Use CASE to implement multiple branches. 3.5 Avoiding multiple exits from cycles. 3.6 The function has only one exit. 3.7 Do not use the condition assignment statement. 3.8 Avoid unnecessary branches. 3.9 Do not use the conditional branch to replace logic expressions.

4. Correctness and fault tolerance requirements

4.1 The program is first correct, followed by beautiful 4.2 Unable to prove that your program has no error, so after writing a program, you should first check. 4.3 Change an error may generate a new error, so the impact on other programs will be considered before modifying. 4.4 All variables must be initialized before calling. 4.5 Enter all user inputs must be checked. 4.6 Do not compare the equal number of floating point numbers, such as: 10.0 * 0.1 == 1.0, not reliable 4.7 Programs and environmental or status relationships, must actively deal with accidents, such as whether the file can be logically locked, whether the printer is online. 4.8 Unit test is also part of programming, and the procedure for submitting a joint test must pass through unit testing.

5. Reusability requirements

5.1 Repeatedly used algorithms or code relative to independent features should be abstract as a common control or class. 5.2 Public controls or categories should consider OO ideas, reduce external contacts, consider independence or encapsulation. 5.3 Public controls or classes should establish a template.

Attached: C programming specification, Delphi made a corresponding reference

.1 scope of application

This standard applies to people developed by Visul C , Borland C ..

.2 variable naming

Naming must have a certain actual meaning, form is xabcfgh, X by variable type, ABC, FGH represents a continuous meaning string, if the consecutive string is only two, can be capitalized. Such as OK.

Specific routine:

Bool type benable;

CH * char chtextc * class object CMAIN (Object instance) h * handle (handle) hwndi * intN * No symbol integer p * pointer SZ, str * string W Wordx, y coordinate

CHAR or TCHAR Type The FileName [10] in the form of the Windows API, otherwise, using the filename [10], single characters can also be represented by lowercase letters; int type ncmdshow;

Long type LPARAM;

UINT type unotify;

DWORD Type DWStart;

PSTR type psztip;


LPTSTR type lpszclassname;





HDC type HDC;

Hinstance Type Hinstance

Handle Type Hinstance,

Hicon type hic;





M_ class member variable m_nval, m_bflagg_ global variable g_nmsg, g_bflag

Several general variables can be used in local variables: NTEMP, NRESULT, I, J (generally used for cyclic variables).

Other resource handles

.3 constant naming and macro

Constants and macro definitions must have certain practical significance;

Constants and macros define between #include and function definitions;

Constants and macro definitions must be written in uppercase letters, the intermediate can be connected with a continuous connection, and each defined right side must have a simple annotation to explain its role;

Resource name definition format:

Menu: IDM_XX or CM_XX

Bittap: IDB_XX

Dialog: IDD_XX

String: IDS_XX


Icon: IDR_XX

.4 function name

Function prototype instructions include reference external functions and internal functions, external references must be indicated on the right side: module name and file name, such as internal functions, as long as the file name is noted;

The first letter must use uppercase letters, requiring the case where the uppercase letter combination specification function is named, if necessary, the interval can be used, as follows:

void updatedb_tfgd (track_name); file: // module name: r01 / sdw.c

Void PrintTrackData; File: // Module Name: R04 / TERN.C

Void ImportantPoint (Void); File: // Module Name: R01 / SDW.C

Void Showchar (int, int, chtype); file: // local module

Void scrollup_v (int, int); file: // local module

.5 structural naming

The structural type naming must all be used in uppercase letters, in principle, the next step is started; the structural variable naming must be combined with uppercase, the first letter must use uppercase letters, if necessary, can be used underline interval. For private data zones, the process thereof must be indicated. Global data definitions simply pay attention to their use.

Examples are as follows:

Typedef struct


Char szproductname [20];

Char szauthor [20];

Char szreleasedate [16];

Char szversion [10];

Unsigned long maxTables;

UNSIGNED Long UsedTables;



6 control naming: Representation with lowercase prefix

Use a lowercase prefix to indicate category: FM window CMD button COM Combo, drop-down list box TXT text input box Labal, tag img image, image Pic Picturegrd Grid, Grid SCR Scroll Bark LST list box FRM FRAM

7 note

In principle, annotations require Chinese;

File start annotation includes: company name, copyright, author name, time, module purpose, background introduction, etc., complex algorithms need to be added with process description;

Function Note includes: input, output, function description, process processing, global variable, call sample, etc., complex functions need to be described in terms of variable purposes;

Comments in the program include: modification time and authors, easy-to-understand annotations, etc .;

Quote 1: Note Template at the beginning of the file

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

** file name:

Company Technology Development Department ********

** founder:

** Japan:

** Modify:

** Japan:

** Description:


** version:

** ------------------------------------------------- -----------------------------

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

Quote 2: Note Template at the beginning of the function

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

** Function name:

** Infit: a, b, c

** a -----

** b ----

** C -----

** output: x ---

** X is 1, indicating ...

** X is 0, indicating ...

** Function Description:

** Global variable:

** Call Module:

** Author:

** Japan:

** Remove:

** Japan:

** version

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

Quote 3: Comment template in the program

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- * /

/ * Comment content * /

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- * /

8 program

a. Program coding strikes simple, clear structure, avoid too much branch structure and too skillful procedures, try not to use recursive mode.

b. When writing a program, you must also want to test the method. In other words, the test plan of "unit test" should be equated to write at the program.

c. Note must be consistent with the program.

d. Modifications after version storage must use the old statement to / * * / closed, unable to delete or modify itself, and record them in the modification record of the file and function.

e. The beginning "{" and "}" of each block in the program must be aligned, nesting blocks, indented a Tab, Tab is 4 space, block type includes if, for, while, do, etc. Keywords are introduced.

f. For a relatively large function, each block and special function call must be indicated, for example, as follows:

Count.divisor = 1193280 / freq; // compute the properties

Outbyte (UNSIGNED SHORT 67, (unsigned char) 182); // Tell 8253 That Acount is coming

Outbyte 66, Count. C [0]); // send low-order byte

Outbyte (UNSIGNED SHORT 66, Count. C [1]); // send high-order byte


BCB, variable naming in Delphi: Follow the Hungarian nomenclature, naming must make sense, formulate the following

Form: Start with uppercase, such as the About copyright form, named WABOUT

File: Start with uppercase, such as the About copyright form, file named fabout.cpp

Button: If you exit buttons, name BTNEXIT


Base class: add BASE tag, such as report base class, form named: wbaserep, file named FBASEREP.CPP


New Post(0)