wiki:ProgramStandards
close Warning:

UltraScan III Programming Standards

Note: The purpose of these standards is to provide a consistent, professional look for the source code. Deviations from the general rules below are acceptable if they enhance the readability of the code.

  • Tabs characters. There should be no embedded tab characters in the source code.
  • Indentation. Normal indentation should be 3 spaces.
  • Braces should generally be on a line by themselves. Example:
for ( i = 1; i = 10; i++ )
{
   if ( test }
   {
      block of code
   } 
}
  • Braces are not required for simple if statements or loops.
  if ( test ) return;
  • Variable declarations.
    1. Each variable declaration should be in a separate line.
    2. Pointers and references should be associated with the type, not the variable name. That is, use the Strostrup and not the K&R style.
    3. If reasonable, line up variable names and any equal signs for assignments.
    4. Group variable definitions of the same type together.
  int     x;
  int     range;
  QLabel* lbl_a;
  double  temperature = 72.0;
  double  y           = 1.2;
  • Class variables. Try to minimize these. When necessary, make public only when truly needed.
  • Spacing.
    1. There should not be a space between a function name and the opening parenthesis.
    2. There should be a space after a programming construct ( if, for, while, etc. )
    3. There should be a space after an opening parenthesis or bracket and before a closing parenthesis or bracket.
    4. There should be a space around operators such as !, =, <=, etc.
  for ( i = 0; i < 10; i++ )
  {
      x[ i ] = function( a, b, c );    
  }
  • Try to keep line lengths to 80 characters or less. Occasionally exceeding 80 characters is OK if a line break would detract from the overall readability.
  • If arguments to a function don't fit nicely on one line, split it like this:
  int lots_of_args( int    an_integer, long  a_long, short a_short,
                    double a_double,   float a_float )
  {
    connect( reply, SIGNAL( error    ( QNetworkReply::NetworkError ) ),
             this,  SLOT  ( postError( QNetworkReply::NetworkError ) ) );
  }
  • Line things up when it makes sense:
  QString lastname   = license.value(  0 );
  QString firstname  = license.value(  1 );
  QString company    = license.value(  2 );
  QString address    = license.value(  3 );
  QString city       = license.value(  4 );
  QString state      = license.value(  5 );
  QString zip        = license.value(  6 );
  QString phone      = license.value(  7 );
  QString email      = license.value(  8 );
  QString platform   = license.value(  9 );
  QString opSys      = license.value( 10 );
  QString version    = license.value( 11 );
  QString validation = license.value( 12 );
  QString expiration = license.value( 13 );

  plot ->setPalette         ( current.plotColor );
  plot ->setCanvasBackground( current.plotBg    );
  grid ->setMajPen          ( QPen( current.plotMajorGrid ) );
  grid ->setMinPen          ( QPen( current.plotMinorGrid ) );
  curve->setPen             ( QPen( current.plotCurve     ) );
  pick ->setRubberBandPen   ( QPen( current.plotPicker    ) );
  pick ->setTrackerPen      ( QPen( current.plotPicker    ) );
Last modified 9 years ago Last modified on Mar 1, 2009 1:50:14 AM