Coding Standards & read "mathematical beauty" felt

Coding Standards & read "mathematical beauty" feelings

l Coding Standards

First, typesetting

1. with appropriate keywords and operators between spaces .

2. Add blank line between independent blocks with the block

3. Longer statements, expressions, etc. to be divided into multiple lines written.

4. partitioned indent the new row to adapt the layout neat, readable statements.

5. Long expression to divide a new line in the low priority operator, the operator of the new line on the first.

6. cycle and judgment statement if the statement or expression longer, will have to be divided adaptation.

7. If the function or process parameters is longer, it will have to be properly divided.

8. do not allow more than the short statement written on one line, that line of writing only one statement.

9. Start function or process, and the cycle definition structure, judgment of code statements have indented style.

10.C / C ++ languages ​​braces '{' and '}' defining a program block, the block write '{' and

'}' Should each separate line in the same column and, while left-aligned with reference to their statements. In the body of the function

Start, class definition, the definition of structure, and the definition of the enumeration if, for, do, while,

switch, case statement to be adopted as a program of indentation.

Second, comments

1. Notes should be simple and straightforward.

2. The side edge writing code comments, modify the code at the same time modify the notes, in order to ensure consistency with the annotated code.

3. Where necessary annotations, to moderate volume. The content of comments to make it clear, clear, precise meaning, prevent

Notes ambiguity . Notes held adjacent thereto description code, i.e., annotations proximity principle.

4. Note that the code should be placed adjacent to the top position, not at the bottom.

5. Note the data structure should be placed adjacent to its upper position, can not be placed below; each domain structure

Note should be placed to the right of this domain; Note the same structure to align different domains.

6. variables, constants should be placed above it notes or rightward adjacent positions.

7. The global variables to have more detailed annotations, including its function, range, or function which processes have access to it

And precautions when accessing instructions.

8. Notes have the necessary information in the header of each source files, including: file name; version number; author; generating

Date; Description Function module (e.g., function, main algorithm, the relationship between the internal portions of the file and its

It documents the relationship, etc.); the main function or procedure list and modify this file history records.

9. Notes have the necessary information, including in front of each procedure or function: a function or procedure name; described function

Above; input, output and return value; call relations and relationships are called descriptions.

Third, naming

1. The shorter word may be formed by removing the abbreviation "vowel";

2. Priority preferably longer words the first few words hair breaks, and explicit expressions in parentheses sequence of operations, to avoid

Free use the default priority.

Fourth, readability

1. Avoid the use of digital easily understood, instead of a meaningful identity.

2. Do not use a high skill statement difficult to understand.

3. The relationship between the source program code should more closely adjacent as possible.

Five variables

1. Remove unnecessary public covariation amount.

2. construct only one module or function can be modified, created, while the rest of the relevant module or function only public access

Variable, function or prevent a number of different modules can be modified to create the same phenomenon common variables.

3. Carefully and clearly define the meaning of common variables, the relationship between the role and the range of public variables.

4. clear public relations function or variable process variables and operation of this public, such as access, modify and create and so on.

5. When passing data to the public variables, to be very careful to prevent unreasonable and so endowed with value or cross-border phenomenon.

6. prevent local variable with the same name and public variables.

7. The layout and structure of carefully designed in the order of elements in the structure can be easily appreciated, to save space, and reduce

Less phenomenon caused by misuse.

8. The structure designed to try to consider backward compatibility and upgrade later, and for some possible future application security

Too aggressive (e.g., leave some space, etc.).

9. A careful and specific language compiler principles of different types of data and relevant details.

10. Do not use uninitialized variables. At the same time declaring variables initialize variables.

11. programming, pay attention to the data type cast .

Sixth, functions, procedures

1. Try to limit the size of the function of less than 200 lines.

2. A function is best done only one function.

3. Write a function is a simple function.

4. Function function should be predictable, i.e. the same as long as the input data should produce the same output.

5. Try not to write a function dependent on other internal functions to achieve.

6. avoid designing function of multiple parameters, the parameters are not removed from the used interface.

7. The effect of the relationship between each parameter, with ranges and parameters detailed comments.

8. All input parameters validity check function.

All non-validity check function 9. The input parameters, such as data files, the public variables.

10. The function name should accurately describe the function capabilities.

11. Avoid using meaningless or ambiguous verb a function named

12. The return value of the function to clear, clear, so that users do not easily ignore the error condition.

13. The function-specific, exact (rather than approximately) function is designed to achieve.

14. The decrease between the recursive function itself or function call.

15. The preparation of reentrant function when, when using global variables should be closed by an interrupt, the signal amount (i.e., P, V operation)

Seven testability

1. Before writing code, should be pre-designed program debugging and testing of methods and tools, and design a good variety of tone

Test code and the corresponding sensing switch functions such as printing and the like.

2. Before carrying out integration testing / system the FBI, to construct a good test environment, test items and test cases, while

Careful analysis and optimization of test cases, in order to improve test efficiency.

Eight, program efficiency

Always pay attention to the efficiency of the code 1. programming.

2. Under accuracy, stability, readability and testability provided to ensure the system software, code efficiency.

3. Can not blindly pursue code efficiency, resulting shadow of accuracy, stability, readability and testability of software

ring.

4. programmed to always pay attention to the efficiency of the code; when optimizing the code, to be thoughtful.

5. To construct carefully or directly call functions written in assembly frequent or high performance requirements.

6. improving space efficiency by improving the structure of the system data and dividing tissue, and program optimization algorithm.

7. In the multi-cycle, should be the busiest in the innermost loop.

8. circulating minimize nesting level.

9. avoid circular body with decision statement, a loop statement should be placed in the code block is determined statements.

10. Instead of possible multiplication or division with other methods, in particular, floating point division.

Nine, quality assurance

1. build software quality in the software design process.

Code quality assurance principles priority

(1) correctness, refers to the program to achieve functional design requirements.

(2) stability, security, the program refers to stable, reliable and safe.

(3) testability, to refer to programs having good testability.

(4) specification / readability, referring to the program coding style, naming rules for compliance.

(5) the overall efficiency refers to the overall efficiency of the software system.

(6) local efficiency refers to the efficiency of itself a module / sub-modules / functions.

(7) Personal expression / personal convenience, refers to personal programming habits.

2. reference only storage space of their own.

3. To prevent references already freed memory space.

4. The procedure / function memory allocated before the procedure / function exits to be released.

(Used to open files) 5. procedures / functions in the application file handle , before the procedure / function to close the exit.

6. The memory operation to prevent cross-border.

7. always pay attention to whether the expression at overflow, underflow.

8. seriously handler can encounter various error conditions.

9. The system runs at the beginning, to initialize the relevant variables and operating environment, prevent uninitialized variable is referenced.

10. The system runs at the beginning, to be loaded into the data system consistency check.

11. The non-random configuration and change settings relating to other modules or systems.

12 can not change the interface with other modules.

13. After fully understand the interface system, then use the function provided by the system.

14. To keep in mind confusing operator. After finish editing program, from start to finish should check again these operators.

15. The statement does not use a lot of relationships with the hardware or operating system, and use the recommended criteria statement.

16. Recommendation: Use third-party software development kit or control when to pay attention to the following points:

(1) fully understand the application interface, note the use of the environment and use.

(2) can not be over-confident of its accuracy.

(3) Unless necessary, do not use unfamiliar third-party toolkits and control.

Ten, code compilation

1. When you write code at any time to pay attention to save, and regular backups, prevent power outages, damaged hard disk and other causes

Missing codes.

2. project within the same group, it is best to use the same editor, and use the same setup options.

3. rational design of software system directory, easy to developers.

4. Open all alarms compiler to compile the program switch.

5. In the same project group or product group, to unify the compiler switch options.

6. Use software tools (such as Visual SourceSafe ) version of the code maintenance.

XI, code testing, maintenance

1. The test unit to at least claim statement coverage .

2. Start the test unit to track each statement, and observe the change of variables and data streams.

3. clean up, organize or optimize the code to be reviewed and tested.

 

Links: https://baike.so.com/doc/8889202-9215009.html

 

l read "mathematical beauty" felt

Be mathematically possible to solve the language problem to the surprise arrived, I started to think that the role of mathematics is usually traded calculate what time, in computer terms is really unexpected use, saw mathematical beauty, only to find that mathematics can solve so many problems, mathematics too wonderful , too unwieldy, with a lot of mathematical problems can be solved.

Talk about probability in mathematics, combined with practical, to see whether the same probability.

The original size of a file depends not only on the number of characters in the file, but also consider the relevance of context and so on.

Search engine so complicated problems, broke view, after refining the original basic Boolean budget. Can simplify complex problems, sometimes complicated problem, we can look for solutions in the basic method, in operation.

Before watching "mathematical beauty", the mathematical sense, the academic world and the real world there is a distance. Read "mathematical beauty" after the discovery of mathematics, the academic world and real life are closely linked. Boolean operations linked to the logic and mathematics, and the probability of natural language and machine linked to a computer ......

A better understanding of the links between courses to learn how to learn the courses are linked to solve a problem, discrete, data structures, etc.

When the algorithm decides to run software usage point the button will perform that step, what page appears, come to any result.

 

This semester would like to achieve with calculator software algorithms.

Guess you like

Origin www.cnblogs.com/666AAAA/p/11478871.html