-
Notifications
You must be signed in to change notification settings - Fork 6
UltraScan III Coding Standards
ehb54 edited this page Mar 1, 2024
·
1 revision
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 at the end of the line. Example:
if ( test ) {
block of code
}
}
- Braces are required for simple if statements or loops.
if ( test ) {
return;
}
- Variable declarations. a. Each variable declaration should be in a separate line. b. Pointers and references should be associated with the type, not the variable name. That is, use the Strostrup and not the K&R style. c. If reasonable, line up variable names and any equal signs for assignments. d. Group variable definitions of the same type together. e. If many variables are defined, alternate groupings may be preferred.
int x;
int range;
QLabel* lbl_a;
double temperature = 72.0;
double y = 1.2;
-
Class variables. Make public only when truly needed.
-
Spacing.
- There should not be a space between a function name and the opening parenthesis.
- There should be a space after a programming construct ( if, for, while, etc. )
- There should be a space after an opening parenthesis or bracket and before a closing parenthesis or bracket.
- 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 132 characters or less. Occasionally exceeding 132 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 ) );