Summarize

posted Dec 2, 2014, 2:34 AM by Javad Taghia

Code review is a valueable place to visit, there are some general guidelines that briefly I'm going through here.

  1. Read this-> Good development practice, the take away messages are:

    • In C/C++, do not use compiler extensions (such as allocating variable-length arrays on the stack, or in-directing through void pointers).

    • building from open sources to get libs don't rely on a lib when don't know the source.

    • in writing C/C++ using GCC, test-compile with -Wall and clean up all warning messages before each release. Compile your code with every compiler you can find — different compilers often find different problems. Specifically, compile your software on true 64-bit machine. Underlying data types can change on 64-bit machines, and you will often find new problems there. Find a UNIX vendor's system and run the lint utility over your software.

    • run tools that for memory leaks and other run-time errors; Electric Fence and Valgrind are two good ones available in open source.

    • don't use compiler-specific features such as the GCC "-pipe" option or nested functions are available. These will come around and bite you the second somebody ports to a non-Linux, non-GCC system.

    • avoid using complex types such as "off_t" and "size_t". They vary in size from system to system, especially on 64-bit systems. Limit your usage of "off_t" to the portability layer, and your usage of "size_t" to mean only the length of a string in memory, and nothing else.

    • never step on the namespace of any other part of the system, (including file names, error return values and function names). Where the namespace is shared, document the portion of the namespace that you use.

  2. code style: as an open source, source matters, so try to check here to get comments about the styles as advantages and disadvantages.

  3. study some well-written open source libs to find a role model if you are beginner like me. Checkhere for a good discussion about this matter.

Comments