* VC Programming specifications

Source: Internet
Author: User

Basic Requirements

1.1ProgramStructure analysis is easy to understand. The number of program lines of a single function cannot exceed 100.
1.2 What are you going to do? It should be simple and straightforward,CodeStreamline and avoid spam.
1.3 try to use standard library functions and public functions.
1.4 do not define global variables at will. Use local variables whenever possible.
1.5 use parentheses to avoid ambiguity.

2. Readability requirements
2.1 readability first, efficiency second.
2.2 keep the comments exactly the same as the code.
2.3 Each source program file has a description of the file header. For details about the specifications, see the specifications.
2.4 each function has a description of the function header. For details about the specifications, see the specifications.
2.5 comments can reflect the meaning of a major variable (structure, union, class, or object) when defining or referencing it.
2.7 Define a constant.
2.8 each stage of the processing process is annotated.
2.9 In typical scenariosAlgorithmThere are comments before.
2.10 use indentation to display the logical structure of the program. The indentation quantity is consistent and the unit is the tab key. 6 tabs are defined.
Bytes.
2.11 The number of cycles and branches must not exceed five layers.
2.12 comments can be in the same line as the statement or in the upstream.
2.13 empty lines and white spaces are also special comments.
2.14 clear statements without comments.
2.15 The scope of comments can be definition, reference, condition branch, and a piece of code.
2.16 The number of comments (excluding program headers and function headers) accounts for 1/5 to 1/3 of the total number of lines.

3. Structured requirements

3.1 two equivalent branches are prohibited.
3.2 disable the GOTO statement.
3.3 Use the if statement to emphasize that only one of the two groups of statements is executed. Disable else Goto and else return.
3.4 use case to implement multiple branches.
3.5 avoid multiple exits from the loop.
The 3.6 function has only one exit.
3.7 The conditional assignment statement is not used.
3.8 avoid unnecessary branches.
3.9 do not replace logical expressions with conditional branches.

4. correctness and fault tolerance requirements

4.1 programs are correct first, followed by beautiful
4.2 it cannot be proved that your program is not wrong. Therefore, after writing a program, you should check it back.
4.3 A new error may occur when an error is changed. Therefore, the impact on other programs should be considered before modification.
4.4 all variables must be initialized before being called.
4.5 all user input must be checked for validity.
4.6 do not compare equal floating point numbers,
For example: 10.0*0.1 = 1.0, unreliable
4.7 when the program is related to the environment or status, it must take the initiative to handle unexpected events, such as whether the file can
Logical locking, whether the printer is online, and so on.
4.8 unit testing is also a part of programming. Programs that submit joint debugging tests must pass unit testing.

5. reusability requirements

5.1 duplicate algorithms or code used to complete relatively independent functions should be abstracted as public controls or classes.
5.2 oo ideas should be taken into account for public controls or classes to reduce external connections and to consider independence or encapsulation.
5.3 a template should be created for public controls or classes.

Appendix: C ++ programming specifications, Delphi for Reference

. 1 Applicability

This standard applies to developers who develop software programs using objective l c ++ and Borland C ++ ..

. 2 variable naming

The name must have some practical significance. The form is xabcfgh, X is determined by the variable type, and ABC and fgh indicate continuity.
Meaning string. If only two consecutive meaning strings can be capitalized, such as OK.

Specific routine:

Bool type benable;

Ch * char chtext
C * Class Object cmain (object instance)
H * handle (handle) hwnd
I * int
N * unsigned integer
P * pointer
SZ, Str * string
W word
X and Y coordinates

If the char or tchar type is directly related to the Windows API, use the szappname [10] format. Otherwise, use
Filename [10] format, a single character can also be expressed in lowercase letters;

Int type ncmdshow;

Long TYPE lparam;

Uint type unotify;

DWORD type dwstart;

Pstr type psztip;

Lpstr type lpcmdline

Lptstr type lpszclassname;

Lpvoid type lpreserved

Wparam type wparam,

Lparam type lparam

Hwnd type hdlg;

HDC;

Hinstance type

Handle type hinstance,

Hicon type hicon;

Int itmp

Float ftmp

Dword dw *

String, ansistring Str *

M _ class member variables m_nval, m_bflag
G _ global variable g_nmsg, g_bflag

The following common variables can be used in local variables: ntemp, nresult, I, j (usually used for cyclic variables ).

Other resource handles are the same as above

. 3 constant naming and macro definition

Constants and macros must have some practical significance;

Constants and macros are defined between # include and function definitions;

Constants and macro definitions must all be written with uppercase letters, and can be connected with underscores (_) based on the continuity of meaning.
A simple comment must be provided on the right of the definition to describe its function;

Resource Name Definition Format:

Menu: idm_xx or cm_xx

Bitmap: idb_xx

Dialog Box: idd_xx

String: ids_xx

Dlginit: dialog_xx

Icon: idr_xx

. 4 function naming

The function prototype description includes reference of external and internal functions. The function source must be indicated on the Right of External Reference: Module
Block name and file name. If it is an internal function, you only need to comment out its definition file name;

The first letter must contain uppercase letters. A combination of uppercase and lowercase letters must be used to name a function. If necessary, an underline is used.
Interval, for example:

Void updatedb_tfgd (track_name); // Module name: R01/SDW. c

Void printtrackdata (track_name); // Module name: r04/tern. c

Void importantpoint (void); // Module name: R01/SDW. c

Void showchar (INT, Int, chtype); // local module

Void scrollup_v (INT, INT); // local module

. 5 struct name

All struct types must be named in uppercase letters. In principle, the preceding dashes start. struct variables must be named in uppercase letters.
A combination of uppercase and lowercase letters. The first letter must contain uppercase letters. If necessary, an underline interval is available. For private data
Data Area, which must indicate the process to which it belongs. You only need to pay attention to the usage of global data definition.

Example:

Typedef struct

{

Char szproductname [20];

Char szauthor [20];

Char szreleasedate [16];

Char szversion [10];

Unsigned long maxtables;

Unsigned long usedtables;

} Dbs_database;

Dbs_database gdatabase;

6. Control name:
Use a lower-case prefix to indicate a category

Use a lower-case prefix to indicate a category:
FM window
CMD button
Cob combo, drop-down list box
TXT text input box
Lab labal, label
IMG image, Image
PIC picture
GRD grid, grid
SCR scroll bar
LST list box
FRM fram

7. Notes

In principle, the annotations must be in Chinese;

The file start comments include: company name, copyright, author name, time, module purpose, background, etc.
A process description must be added to a complex algorithm;

Function annotations include: input, output, function description, process processing, global variables, call samples, and other complex functions.
Variable usage instructions must be added;

Comments in the program include: modification time and author, easy to understand comments, etc;

Reference 1: annotation template at the beginning of a file

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

** File Name:

** Copyright (c) 1998-1999 ********** Technology Development Department of the company

** Creator:

** Date:

** Modifier:

** Date:

** Description:

**

** Version:

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

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

Reference 2: annotation template at the beginning of a function

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

** Function Name:

** Input: A, B, C

** ---

** B ---

** C ---

** Output: X ---

** X is 1, indicating...

** X is 0, indicating...

** Function description:

** Global variables:

** Call module:

** OPERATOR:

** Date:

** Modification:

** Date:

** Version

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

Reference 3: annotation template in the program

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

/* Comment */

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

8 programs

A. program coding strives to be concise and clear, avoiding too many branch structures and too skillful programs,
Do not use recursive mode.

B. When writing a program, you must also think about the test method. In other words, the unit test plan should be
Compile the program together.

C. The annotation must be consistent with the program.

D. The old statement must be closed with/**/after version archive. The old statement cannot be deleted or modified on its own, and
Record the changes to files and functions.

E. "{" and "}" at the beginning of each block in the program must be aligned. each nested block must be in one set,
Indent a tab with four spaces. The block type includes keywords such as if, for, while, and do.

F. For a relatively large function, each block and special function call must specify its function. For example:

:

Count. divisor = 1193280/freq; // compute the proper count

Outbyte (unsigned short) 67, (unsigned char) 182); // tell 8253 that
Count is coming

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

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

××××××××××××××××××××××××××××××××××××××××××

Name the variable in BCB and Delphi:

According to the Hungarian naming law
The name must be meaningful.

Form: Start with W in uppercase. For example, the copyright form of about is named wabout.

File: start with an uppercase value of F, such as the about copyright form. The file is named fabout. cpp.

Button: for example, the exit button is named btnexit.

......

Base Class: adds a base tag, such as a report base class. The form is named wbaserep and the file is named fbaserep. cpp.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.