Coding Guidelines

I am a little over the top sometimes when it comes to code formatting lol, i like code to look neat since it makes it easier for us to read and although its different for everyone we need to keep some kind of standard so mine has been a mix of GNU Coding Standards and Drizzle Coding Standards. Although i have to explain the language crules its coding guidelines within the project at the end on its own.

Interpreter Code

If your an emacs user like me you can't really go wrong, emacs should keep you right, but i have some small things i like to keep the same for example:

Conditionals

NO!

if(a == b && c == j || A)
  do_something( );

YES!

if( ((a == b) && (c == j)) || A )
   do_something( );

Preincrement and Predecrement

NO!

size_t i;
for( i= 0; i<strlen("bla"); i++ )
{
...
}

YES!

size_t i= 0;
for( ; i<strlen("bla"); ++i )
{
...
}

Use prefix form (++iter) of the increment and decrement operators with iterators and other template objects. A fairly good explanation why.

Assignments and Expressions

NO!

unsigned int x = 7;
unsigned int y = 5 + x;

YES!

unsigned int x= 7;
unsigned int y= 5 + x;

Calls

NO!

ret= function(x,y,z);

YES!

ret= function( x, y , z );

Indentation

NO!

int foo ( unsigned int param_a, unsigned int param_b, unsigned int param_c ) {
        printf("some stuff");
        if( param_a < param_b ) {
                printf("....");
        }
        return;
}

YES!

int foo( unsigned int param_a,
         unsigned int param_b,
         unsigned int param_c )
{
  printf("some stuff");
 
  if ( param_a < param_b )
    {
      printf("....");
    }
 
  return;
}

Function and Method Comments

/**
 * @brief
 *   Return the sum of two positive integers.
 *
 * @details
 *   Adds x and y and returns the result in z.
 *
 * @param[in] x First integer
 * @param[in] y Second integer
 * @param[out] z Holds the result of x+y
 *
 * @retval 0 success
 * @retval 1 failure, ints were not positive
 */
int sum( int x, int y, int *z )
{
  if( x < 0 || y < 0 )
    return 1;
 
  *z= x + y;
 
  return 0;
}
 
coding.txt · Last modified: 2009/11/17 23:33 by redbrain
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki