Code Review Checklist

xiaoxiao2021-03-06  41

The following is the circulating code review checklist, I don't take the liberty, save everyone, translate as follows.

It is inevitable that it is inevitable.

I hope that you can help you at your heart and the future work. :)

TERRY 2003/12/18

Code Review Checklist

The following is a Macadamian's guide for developer code REVIEW. Before the code is submitted, they should check the following rules. We publicize this checklist is to provide a brief reference to any development department's peer code review. You can start review directly according to this table, of course, a better way is to use it in accordance with the actual modification of the development. Catalog General Code Smoke Test Universal Test Comments and Coding Conventions Comments and Coding Error Handling Error Handling Resource Leaks resource leaks Control Structures Control structures Performance Performance Functions function Bug Fixes bug fix Math Math General Code Smoke Test Universal Test Does the code build correctly? No Errors Should Occur When Building The Source Code. No Warnings Should Be Introducted By Changes Made To The Code. Correctly Compile: There is no error when compiling code. Does the code execute as expected? WHEN EXECUTED, The code does what it is supposed to execute if the expected results? Do you understand the code you are review? As a reviewer, You Should Understand The code. If you do ', The Review May Not Be Complete, or The Code May Not Be Well Comment. You understand the code that is under the Review (review) Yet? As a reviewer, you should understand these code; otherwise it will lead to insufficient evaluation or no effect. HAS THE Developer TESTED TESTED? INSURE The Developer Has Unit Tested The Code Before Sending It for Review. All The Limit Cases Should Have Been Tested. Make sure the developer has tested the code. Before submitting the review, make sure the developer has completed the unit test of the code. All possible conditions should be tested. Comments and Coding Conventions Comments and Coding Does the code respect the project coding conventions? Check that the coding conventions have been followed. Variable naming, indentation, and bracket style should be used. Whether the code to follow coding style items? Check if the coding style has followed, such as variable naming, regeneration, parentheses, etc. Does the source file start with an appropriate header and copyright information? Each source file should start with an appropriate header and copyright information. All source files should have a comment block describing the functionality provided by the file. Source code files have the appropriate header and Copyright information begins.

Are variable declarations properly commented? Comments are required for aspects of variables that the name does not describe. Each global variable should indicate its purpose and why it needs to be global. Is there an appropriate variable declarations comment. Especially global variables, it is necessary to indicate the purpose of the state as a global, and the reason. Are Units Of Numeric Data Clearly StateD? For example, if a number represents length, indeicate if it is in feet or meters. Numerical data blocks are clearly described. For example, if a number represents the length, it should indicate that the unit is feet or meter. Are all functions, methods and classes documented? Describe each routine, method, and class in one or two sentences at the top of its definition. If you can not describe it in a short sentence or two, you may need to reassess its purpose IT Might Be a Sign That The Design Needs to Be Improved. All functions, methods, and classes are officially described. In the definition program, method, class, describe them with one or two short words. If you cannot describe it within one or two sentences, you should reconsider its purpose; this is also a signal that needs to improve the design. Are Function Parameters Used for Input or Output Clearly Identified AS Such? Make it it. Clear Which parameters is used for input and output. Does all functions have been clearly expressed? Are complex algorithms and code optimizations adequately commented? Complex areas, algorithms, and code optimizations should be sufficiently commented, so other developers can understand the code and walk through it. Complex algorithms and code optimization requires enough comments. To ensure that developers can understand and review. Does code that has been commented out have an explanation? There should be an explanation for any code that is commented out. "Dead Code" should be removed. If it is a temporary hack, it should be identified as such. Commented code Is there an explanation? "Dead code" must be deleted.

Are comments used to identify missing functionality or unresolved issues in the code? A comment is required for all code not completely implemented. The comment should describe what's left to do or is missing. You should also use a distinctive marker that you can search for later (For example: "Todo: Francis"). The lack of function functions, there is no completely solving problem that needs to be annotated. Note To describe the remaining work and missing things. It is best to add a tag to find, for example, "Todo: Fancis". Error Handling Error Handling Are assertions used everywhere data is expected to have a valid value or range? Assertions make it easier to identify potential problems. For example, test if pointers or references are valid. Assertions or wherever you need a valid value range . Such as pointers and references. Are errors properly handled each time a function returns? An error should be detected and handled if it affects the execution of the rest of a routine. For example, if a resource allocation fails, this affects the rest of the routine if it uses that resource .............................. .. If the error affects the execution of the next program (such as resource allocation failure), you can usually write the log file to handle it. Are RESOURCES AND MEMORY RELEASED IN ALL ERROR PATHS? Make Sure All Resources and memory allocated are release in the error Paths. Make sure that all resources include memory allocation being released. Are All Thrown Exceptions Handled Properly? If The Source Code Uses A Routine That Throws An Exception, There Should Be A Function In The Call Stack That Catches IT and Handles It Properly. All thrown exceptions are properly processed. If an exception is thrown, there should be a corresponding Catch function.

Is the function caller notified when an error is detected? Consider notifying your caller when an error is detected. If the error might affect your caller, the caller should be notified. For example, the "Open" methods of a file class should return error Class of the Class Will Be Hands To The Calid BE The Calls To The Caller Might BE Intested In Doing Some Error Handling Of ITS OWN. It is best to notify the caller. HAS ERROR HANDLING CODE BEEN TESTED? DON 'THAT THAT THATE ERROR HANDLING CODE THAT THATE TEST CASES That Exercise It. Errors Have the code has been tested. Resource Leaks Resource Leak Is allocated memory (non-garbage collected) freed? All allocated memory needs to be freed when no longer needed. Make sure memory is released in all code paths, especially in error code paths. Allocation of resources have been released ? All resources (memory) should be released without use. Special attention is considered under abnormal conditions. Are all objects (Database connections, Sockets, Files, etc.) freed even when an error occurs? File, Sockets, Database connections, etc. (basically all objects where a creation and a deletion method exist) should be freed even when an error occurs. For example, whenever you use "new" in C , there should be a delete somewhere that disposes of the object. Resources that are opened must be closed. For example, when opening a file in most development environments, you need to call A Method to Close The File When You're Done. Even if an exception occurs, all objects (data connection, sockets, and files, etc.) are released. The resource is turned on and there should be closed. Is The Same Object RELEASED MORE THAN ONCE? Make Sure The Same Object Is Released More Than Object. Check Error Code Paths. Do not release the same object. Check the situation of exception processing code.

Does the code accurately keep track of reference counting? Frequently a reference counter is used to keep the reference count on objects (For example, COM objects). The object uses the reference counter to determine when to destroy itself. In most cases, the developer Uses Methods to Increment Or Decrement The Reference Count Reflects The Numr of Times An Object Is Referred. Make sure the code is synchronized with reference counting. The SmartPointer is allowed to be used in P.S .: STL, not the reference count (see the Shared_PTR class in the open source Boost library, or see a simpler AUTO_PTR class in STL). There are related applications in COM. Thread Safeness thread safety Are all global variables thread-safe? If global variables can be accessed by more than one thread, code altering the global variable should be enclosed using a synchronization mechanism such as a mutex. Code accessing the variable should be enclosed with All global variables are threads. If you allow more than one thread to access global variables, mechanisms such as mutual exclusion should be used. Are objects accessed by multiple threads thread-safe? If some objects can be accessed by more than one thread, make sure member variables are protected by synchronization mechanisms. Multithreading ensure safe access (access) object. Are locks released in the same order they are obtained? It is important to release the locks in the same order they were acquired to avoid deadlock situations. Check error code paths. In the same order to unlock the order in which they obtained in order to avoid a deadlock occurs .

Is there any possible deadlock or lock contention? Make sure there's no possibility for acquiring a set of locks (mutex, semaphores, etc.) in different orders. For example, if Thread A acquires Lock # 1 and then Lock # 2, then Thread B Shouldn't Acquire Lock # 2 and the Lock # 1. Is there possible deadlock or threads to compete for resources? Control Structures Control structures Are loop ending conditions accurate Check all loops to make sure they iterate the right number of times Check the condition that ends the loop;?. Insure it will end out doing the expected number of iterations ending cycle conditions is accurate.? Check the number of increments, cycle end conditions. Is The Code Free of Unintended Infinite Loops? Check for CHECK for CODE PATHS That Cause Infinite Loops Will Be Met Unless OtherWise Documented. The code does not fall into an infinite loop. Check the code path that may cause infinity cycles. Performance Performance Do recursive functions run within a reasonable amount of stack space? Recursive functions should run with a reasonable amount of stack space. Generally, is better. Recursive functions run in a reasonable amount of stack space it to code iterative functions. Are whole objects duplicated when only references are needed? This happens when objects are passed by value when only references are required. This also applies to algorithms that copy a lot of memory. Consider using algorithm that minimizes the number of object duplications, reducing the data Does all object copies do you need to quote? Minimize the memory data that needs to be transmitted.

Does the code have an impact on size, speed, or memory use? Can it be optimized? For instance, if you use data structures with a large number of occurrences, you might want to reduce the size. Code affect the size of the structure , Speed ​​and memory use? Can I optimize? Are you using blocking system calls when performance is involved? Consider using a different thread for code making a function call that blocks. Is the code doing busy waits instead of using synchronization mechanisms or timer events? Doing busy waits takes up CPU time. It is a better practice to use synchronization mechanisms. Was this optimization really needed? optimizations often make code harder to read and more likely to contain bugs. Such optimizations should be avoided unless a need has been identified. has the code been profiled? Functions Are function parameters explicitly verified in the code? This check is encouraged for functions where you do not control the whole range of values ​​that are sent to the function. This is not the case for helper functions, for instance. Each function should check its parameter for MINIMUM AND MAXIMUM POSIBLE VALUES. Each Pointer or Reference Should Be Checked To See if IT IS NULL. An Error OR AN Exception Should Occur IF A Parameter Is Invalid. Are Arrays Explicitly Checked for Out-of-Bound Indexes? make Sure An Error Message IS DISPLAYED IF An Index Is Out-of-Bound. Are Functions Returning References To Objects Declared On The Stack? DON '

t return references to objects declared on the stack, return references to objects created on the heap. Are variables initialized before they are used? Make sure there are no code paths where variables are used prior to being initialized. If an object is used by more than one thread, make sure the object is not in use by another thread when you destroy it. If an object is created by doing a function call, make sure the object was created before using it. Does the code re-write functionality that could be achieved by using an existing API? Do not reinvent the wheel. New code should use existing functionality as much as possible. Do not rewrite source code that already exists in the project. code that is replicated in more than one function should be put in a helper function for easier maintenance. Bug Fixes Bug fix Does a fix made to a function change the behavior of caller functions? Sometimes code expects a function to behave incorrectly. Fixing the function can, in some cases, break the cal Ler. if this happens, EIG. IF THE CODE THAT DEPLEN AND The Function, or Add a comment explaining why the code can't be change. Fixing the bug causes the call function to change. Does the bug fix correct all the occurrences of the bug? If the code you're reviewing is fixing a bug, make suxes all the occurrences of the bug. Don't correct all concurrent possible errors for the bug fix. (Can not introduce new Bug) Math mathematical considerations Is the code doing signed / unsigned conversions Check all signed to unsigned conversions:?? Can sign completion cause problems Check all unsigned to signed conversions: Can overflow occur Test with Minimum and Maximum possible values? Does the code have a symbol / unsigned conversion? Symbol -> No symbol, no problem? No symbol -> Is there a symbol, is there an overflow? Test it with the largest and minimum.

The following is the circulating code review checklist, I don't take the liberty, save everyone, translate as follows. It is inevitable that it is inevitable.

I hope that you can help you at your heart and the future work.

TERRY 2003/12/18

转载请注明原文地址:https://www.9cbs.com/read-63716.html

New Post(0)