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.
- Each variable declaration should be in a separate line.
- Pointers and references should be associated with the type, not the variable name. That is, use the Strostrup and not the K&R style.
- If reasonable, line up variable names and any equal signs for assignments.
- 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.
- 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 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 ) );
Editor Notes
emacs:
- This code should be inserted in ~/.emacs. Executing "Esc-x usindent" will indent the file.
(setq c-basic-offset 3) (setq c-offsets-alist '((substatement-open . 0))) (setq vc-handled-backends nil) (defun select-previous-window () "Switch to the previous window" (interactive) (other-window -1)) (global-set-key (kbd "C-x p") 'select-previous-window) (setq-default indent-tabs-mode nil) (fset 'usindent "\C-[<\C-[%\C-q\C-i\C-m \C-m!\C-[<\C-xh\C-[\C-\\")
kdevelop - use the following steps to configure (see attached kdevelop.png file image):
1. load a C++ file 2. go to "Settings" 3. "Configure Editor..." 4. Select "Indentation" in left scroll bar 5. Select "Indentation mode: C Style" 6. "Insert leading Doxygen "*" when typing is _off_ 7. "Use spaces instead of tabs to indent" is _on" 8. "Emacs style mixed mode" - set to _off_ 9. "Number of spaces" - set to "3" 10. "Keep indent profile" - set to _on_ 11. "Keep extra spaces" - set to _off_ 12. "Tab key indents" - set to _on_ 13. "Tab Key Mode if Nothing Selected" - "Insert indent characters" is set to on, all others are set to _off_
Last modified 10 years ago
Last modified on May 2, 2009 2:18:55 AM
Attachments (2)
-
.emacs
(380 bytes) -
added by emre 10 years ago.
Emacs file for editing source code
- kdevelop.png (81.7 KB) - added by demeler 10 years ago.
Download all attachments as: .zip