Code Quality Control & Programming items

It is important to note that, to ensure code quality and efficiency for programming and programming problems arising in the work record


 

 

Code quality control

  1. Note Programming items when writing a program to ensure the quality of the code format / performance
  2. After the program is completed self-test all the changes required, and detailed notes on changes in the content of JIRA;
    also use the tool to check memory leak valgrind / memory bounds, confirmation function is normal
  3. After the self-test is complete, and the development of pre-contrast codes, strict checking it twice before the conflict commit code

Programming items

  1. When submitting the code, the need for strict conflict checking it twice, modify the code to prevent unrelated functions 
    should be several times compared with the pre-developed code before the code after submission to ensure that no modifications to the code function is not related

  2. For determination logic, it can be judged in advance as much as possible to make in advance can reduce the code execution back to submit efficiency

  3. Not to facilitate replication (any) Code   

  4. When increasing the logic in a conditional statement, need to consider whether this part of the logic will be triggered, if not trigger will not affect the function of
    the same, when adding a new logic, we must determine whether this part of the logic required to perform (may it needs to be triggered only under certain conditions)

  5. Exception handling code / recording part of the log, will be needed for access to information / print log in to quickly locate the problem from, from this perspective as well as to select the level throw exception handling logs / catch position     
    interfaces are typically required external calls recording the time it takes to call, no response can be prolonged by a log for the interface / slow due to the return of
     
    all affected (executed on the branch) content output log, the log output are possible to confirm what kind of cause of this result is generation

  6. Can obtain the configuration of the relevant module configuration After each increase, the need to increase the memory dump the contents of the current program code configured for remote troubleshooting

  7. For static types of variables / function, we need to take into account the security thread
    in particular Env variables in

  8. When generating / using the pointer, it must determine whether it is valid, otherwise easily lead to mistakes caused the program to crash

  9. Never trust user input for data (user input) do not generate its own processing / parsing must be considered abnormal, do a comprehensive judgment

  10. Consume memory / CPU operation should try in cycle / function outer achieve
    operation such as parsing the message header, the format / character set conversion, to minimize the memory / CPU consumption, and function calls

  11. Note that the code compatibility
    of new features not affect the old code, the other in self-test process requires too old functional unit testing to ensure compatibility

  12. In dealing with expression evaluation, we need to pay attention to overflow and divide by zero problems
    such as this line of code, int limit when approaching the nCosLimt, in the expression on the right multiplied by the rate will become negative overflow limit, divide by 100 after the resulting value is still negative, contrary to expectation
// 检查邮件数量是否超过 cos 上限
static_cast<int>(MBoxHdr.getTotalMsgCount()) >= nCosLimit * 
static_cast<int>(nMailCntQuotaWarningRate) / 100)

In addition, when the dividend is a variable, you need to pay attention to whether the variable may be 0

Code optimization & features

Code optimization

Upon completion of a demand, you need to do the following checks to determine whether there is room for optimization

  1. When the multi-block is not a function associated with the presence of logic, the simple logic function on the front, on the back of the complex can be determined in advance in advance
    if the function has a plurality of outlets, it runs the complex logic may be affect performance, simple logic and throws an exception if the intermediate result in a jump, the original can not be executed should be executed

  2. Repeated code needs to judge whether the merger / Abstract
    (80% -90% identical) to substantially the same logic can be encapsulated need to consider whether a function is determined by the execution state parameters
    for the independent variable relates to a data structure of & logic, can be abstracted into classes, according to the behavior of different configurations determined parameters

Function & optimization module

Optimize processes a module / function

  1. Carding current correlation logic / function
  2. Analysis of the advantages and disadvantages of existing models, which implementation is unreasonable, where there is room for optimization, which is the main part of the process affect performance
  3. Optimized for the results of the analysis done, the design of new realization

other

  1. In the preparation aspect of the document, it is necessary to comply with the principle of minimum
    i.e. increased only relevant to the needs / problem description / log / configuration, easier for people to understand and maintain;
    and increase the log needs to be able to support (interpretation) described steps, the output content needs to clear, to select the appropriate log level depending on the circumstances
     
  2. Encounter an unfamiliar system log, which need to check each field
    is determined by comparing the normal log which point there is a problem
     
  3. The safe operation of a system should have a special user to perform
    such a dedicated tomcat user: tomcat, coremail users have a special coremail users
    need to separate the user and the root user program execution, when coremail user is compromised, it will not have root user privileges; further, then, the system will add the user program cmadm write permissions defined as cmadm, coremail normal use to the user-readable executable permissions, and arranged to modify / write access log

Tips

  1. throw again in the catch can be intercepted an exception thrown try again
{
    try
    {
        ...
    }
    catch(TException & te)
    {
        if(condition)
            throw;      // 会跳至外层的 catch 处理
    }
}
catch(TException & te)
{
    ...
}

debugging

  1. When the problem is not clear at what part of the code, the code portion may be modified to narrow the problem commented

Guess you like

Origin www.cnblogs.com/chenxinshuo/p/11970629.html