[[AxisCPPProjectPages]]

This is the proposed coding convention for Axis C++ project.

The coding convention is based on the Apache Developers' C Language Style Guide


A Coding Convention for Axis C++ Code

Revision 0.0 2004/03/30 by Samisa Abeysinghe: initial draft

Revision 0.1 2004/04/01 by Damitha: Fix {} conflict, Added long line breaking and doxygen commenting guidelines

Revision 0.2 2004/04/01 by Samisa Abeysinghe: Did some visual formatting

== Purpose == ex: To enhance readability and maintainability of Axis C++ code.

Definitions

Identifier Names

Pointers and References

Indentation, General Style

{{{ ClassName/methodName {     //statements;  }

{{{ ControlStructureSyntax {   //statements  }

Class Declarations

Classes are declared in the following order: public member functions, protected member functions, private member functions, protected data members, and private data members. It is advisable not to declare any public data members. Constructors should be on the top of the member function list, followedby destructor and finally the other member functions. e.g:

 class SOAPApplication 
{
public:
{{{    SOAPApplication(); 
    ~SOAPApplication(); 
    void run(); 
    int parseMessage( char * pcMessage ); 

protected:     void trackSession();  private:     int m_iRequestCount;  };

Control Structures

The control structures are as follows:

if (expression) 
{
{{{    statements; 

} else {     statements;  }

for (expression; expression; expression) {     statements;  }

do {     statements;  } while (expression);

while (expression) {     statements;  }

switch (expression) { case constant: {{{ statements;

default: {{{ statements;

}

Expressions

Space before and after assignment and other and operators. No space between unary operators (increment, decrement, and negation) and the lvalue. Examples:

    a = b 
    a + b 
    a < b 
    a = -b 
    a = !b 
    ++a 

Statements

Function calls

Ex: MyMethod(type arg1, type2 arg2);

Comparisons against constants

Ex: if (AXIS_SUCCESS != iStatus)

Checking pointers

Ex: "if (pPointer == NULL)" should be avoided and instead "if (pPointer)" should be used.

Long lines

Number of columns in a line should be <= 80. If a line exceeds this, it should be taken into the next line after breaking in a proper place. The break point could be a space or any other special symbol used in the language. Next line starts with four spaces indented.

    if ((LOBYTE(wsaData.wVersion) < WS_VERSION_MAJOR()) || 
        (LOBYTE(wsaData.wVersion) == WS_VERSION_MAJOR() && 
         HIBYTE (wsaData.wVersion) < WS_VERSION_MINOR())) 
    { 

Comments

/*
{{{ * long comments which need more than one line use 
 * this block comment style, for both C and C++ 
 */ 

statement; statement; // short C++ comments

Doxygen commenting conventions as described in the following link is suggested. Note that Axis C++ already use this convention in the existing code.

URL: http://www.nbirn.net/Resources/Developers/Conventions/Commenting/C_Comments.htm#Documenting

File Names

    Revision rivision_no date by author_full_name 
    Short description of the update done 

References

Apache Developers' C Language Style Guide - URL:http://www.apache.org/dev/styleguide.html

Doxygen commenting syntax - URL: http://www.nbirn.net/Resources/Developers/Conventions/Commenting/C_Comments.htm#Documenting


Coding%Convention (last edited 2009-09-20 23:33:34 by localhost)