About offer high-quality code to prove safety

Copyright: welcome the exchange of learning, please indicate the source. https://blog.csdn.net/qq_23869697/article/details/91473066

study notes

Gangster views

(1) code better fault tolerance
(2) basic knowledge can not be wrong
(3) can not tolerate non-compliance function, boundary conditions, special circumstances not thinking clearly
(4) of code writing is not standardized
(5) to the correctness and robustness nature are done, attention to check the output parameters, handling errors and exceptions way, code specifications

Code normative questions

Three areas: writing, layout, name
written: The main thing to note when whiteboard programming;
layout: Note indentation, braces and other issues
named:
here a brief summary of some of the python named:
(1) module to make use of lowercase name, initials remain lowercase, try not to use the underscore (unless more than one word, and a small number of cases)
(2) class names use camel (CamelCase) naming style, the first letter capitalized, a leading underscore private classes available
(3) function name all lowercase , if a plurality of words, separated by an underscore
(4) possible variable names in lower case, if a plurality of words, separated by an underscore
(5) separated by the constant use underlined uppercase name

Code integrity issues

Think first before writing the code input is what
three questions to ask yourself:
(1) the code to achieve the basic functionality?
(2) Enter the border to get the correct output value of it?
(3) the illegal export was reasonable error handling it?
Test code should be written based on these three issues.

The common boundary condition represents the range of an integer, a string like shaping transfer.

Error handling

(1) returns an error value
(2) define a global variable, the variable assignment error to
(3) Throws
commonly thrown exception is informed of an error code in python.

Robustness

Defensive programming, anticipate possible problem areas, develop ways to deal with problems that may arise.

Guess you like

Origin blog.csdn.net/qq_23869697/article/details/91473066