Basic Requirements
1.1 program structure analysis, 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, straightforward, and the code should be streamlined to avoid spam.
1.3 try to use standard library functions and public functions.
1.4
Do not define global variables. Use local variables whenever possible.
1.5 use parentheses to avoid ambiguity.
2. Readability requirements
2.1 readability first, efficiency second.
2.2
Make sure that the comments are consistent with 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.
2.7 Define a constant.
2.8
Each stage of the processing process is annotated.
2.9 annotations are provided before typical algorithms.
2.10
Use indentation to display the logical structure of the program. The indentation quantity is consistent and the unit is tab key. 6 tabs are defined.
Bytes.
2.11 The number of cycles and branches must not exceed five layers.
2.12
The comment can be in the same line as the statement or in the uplink.
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 if
Statement. 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 prove 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 that 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 the use of objective l c ++, Borland
C ++ software development personnel ..
. 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
Char or tchar type and windows
Szappname [10] is used for API direct connection. Otherwise
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 type
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 side 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 the file
/*************************************** ***************************
**
File Name:
** Copyright (c) 1998-1999 ********** Technology Development Department of the company
** Creator:
**
Date:
** Modifier:
** Date:
** Description:
**
** Version
BEN:
**--------------------------------------------------------------------------
---
**************************************** **************************/
Reference 2:
Annotation template at the beginning of the 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:
** Repair
Change:
** Date:
**
Version
**************************************** ************************/
Reference 3:
Annotation template in the program
/*----------------------------------------------------------*/
/*
Comment content
*/
/*----------------------------------------------------------*/
8
Program
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" test plan should be
Compile the program together.
C.
Note must be consistent with the program.
D. Make sure to use the old statement/**/for any modifications after version archive /**/
Closed, cannot be deleted or modified by yourself, 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 has one set,
Indent a tab, Tab
Contains four spaces. The block type is derived by keywords such as if, for, while, and do.
F. For larger functions, each block
And special function calls must indicate their functions, 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:
Starting with W, for example, about copyright form,
Name it 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:
Add the base tag, such as the report base class. The form is named wbaserep and the file is named fbaserep. cpp.