mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
codingStyleGuide: updated and generated the pdf version. GUIDELINES removed.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
#
|
||||
#+TITLE: OpenFOAM C++ style guide
|
||||
#+AUTHOR: OpenCFD Ltd.
|
||||
#+DATE: April 2010
|
||||
#+DATE: May 2010
|
||||
#+LINK: http://www.opencfd.co.uk
|
||||
#+OPTIONS: author:nil ^:{}
|
||||
|
||||
@ -13,9 +13,9 @@
|
||||
+ The normal indentation is 4 spaces per logical level.
|
||||
+ Use spaces for indentation, not tab characters.
|
||||
+ Avoid trailing whitespace.
|
||||
+ The body of control statements (eg, if, else, while, etc).
|
||||
+ The body of control statements (eg, =if=, =else=, =while=, etc).
|
||||
always delineated with brace brackets. A possible exception can be
|
||||
made with 'break' or 'continue' as part of a control structure.
|
||||
made with =break= or =continue= as part of a control structure.
|
||||
|
||||
+ stream output
|
||||
+ =<<= is always four characters after the start of the stream,
|
||||
@ -72,16 +72,16 @@
|
||||
\*---------------------------------------------------------------------------*/
|
||||
#+END_EXAMPLE
|
||||
|
||||
*** The =.H= Files
|
||||
*** The /.H/ Files
|
||||
+ header file spacing
|
||||
+ Leave two empty lines between sections
|
||||
(as per functions in the =.C= file etc)
|
||||
(as per functions in the /.C/ file etc)
|
||||
|
||||
+ use "//- Comment" comments in header file
|
||||
+ use =//- Comment= comments in header file
|
||||
+ add descriptions to class data and functions
|
||||
+ destructor
|
||||
+ If adding a comment to the destructor -
|
||||
use //- and code as a normal function:
|
||||
use =//-= and code as a normal function:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
//- Destructor
|
||||
@ -89,11 +89,11 @@
|
||||
#+END_EXAMPLE
|
||||
|
||||
+ inline functions
|
||||
+ Use inline functions where appropriate in a separate classNameI.H file.
|
||||
+ Use inline functions where appropriate in a separate /classNameI.H/ file.
|
||||
Avoid cluttering the header file with function bodies.
|
||||
|
||||
*** The =.C= Files
|
||||
+ Do not open/close namespaces in a =.C= file
|
||||
*** The /.C/ Files
|
||||
+ Do not open/close namespaces in a /.C/ file
|
||||
+ Fully scope the function name, i.e.
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
@ -113,7 +113,7 @@
|
||||
|
||||
EXCEPTION
|
||||
|
||||
When there are multiple levels of namespace, they may be used in the =.C=
|
||||
When there are multiple levels of namespace, they may be used in the /.C/
|
||||
file, i.e.
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
@ -138,7 +138,7 @@
|
||||
+ const
|
||||
Use everywhere it is applicable.
|
||||
|
||||
+ variable initialisation using "="
|
||||
+ variable initialisation using =
|
||||
|
||||
: const className& variableName = otherClass.data();
|
||||
|
||||
@ -169,7 +169,7 @@
|
||||
}
|
||||
#+END_EXAMPLE
|
||||
|
||||
NOT (no space between "if" and "(")
|
||||
NOT (no space between =if= and =(=)
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
if(condition)
|
||||
@ -201,7 +201,7 @@
|
||||
}
|
||||
#+END_EXAMPLE
|
||||
|
||||
NOT (no space between "for" and "(")
|
||||
NOT (no space between =for= and =(=)
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
for(i = 0; i < maxI; i++)
|
||||
@ -245,7 +245,7 @@
|
||||
**** Splitting return type and function name
|
||||
+ split initially after the function return type and left align
|
||||
|
||||
+ do not put "const" onto its own line - use a split to keep it with
|
||||
+ do not put =const= onto its own line - use a split to keep it with
|
||||
the function name and arguments.
|
||||
|
||||
so
|
||||
@ -277,7 +277,7 @@
|
||||
#+END_EXAMPLE
|
||||
|
||||
+ if it needs to be split again, split at the function name (leaving
|
||||
behind the preceding scoping "::"s), and again, left align, i.e.
|
||||
behind the preceding scoping =::=s), and again, left align, i.e.
|
||||
|
||||
For example,
|
||||
|
||||
@ -326,16 +326,19 @@
|
||||
|
||||
*** Maths and Logic
|
||||
+ operator spacing
|
||||
+ a + b, a - b
|
||||
+ a*b, a/b
|
||||
+ a & b, a ^ b
|
||||
+ a = b, a != b
|
||||
+ a < b, a > b, a >= b, a <= b
|
||||
+ a || b, a && b
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
a + b, a - b
|
||||
a*b, a/b
|
||||
a & b, a ^ b
|
||||
a = b, a != b
|
||||
a < b, a > b, a >= b, a <= b
|
||||
a || b, a && b
|
||||
#+END_EXAMPLE
|
||||
|
||||
+ splitting formulae over several lines
|
||||
|
||||
Split and indent as per "splitting long lines at an "=""
|
||||
Split and indent as per "splitting long lines at an ="
|
||||
with the operator on the lower line. Align operator so that first
|
||||
variable, function or bracket on the next line is 4 spaces indented i.e.
|
||||
|
||||
@ -525,9 +528,9 @@
|
||||
option.
|
||||
|
||||
The documentation for a particular application is normally contained
|
||||
within the first comment block in a =.C= source file. The solution is this
|
||||
to invoke a special filter for the "applications/{solver,utilities}"
|
||||
directories that only allows the initial comment block for the =.C= files
|
||||
within the first comment block in a /.C/ source file. The solution is this
|
||||
to invoke a special filter for the "/applications/{solver,utilities}/"
|
||||
directories that only allows the initial comment block for the /.C/ files
|
||||
through.
|
||||
|
||||
The layout of the application documentation has not yet been finalized,
|
||||
@ -551,10 +554,7 @@
|
||||
myClass.initialize()
|
||||
#+END_EXAMPLE
|
||||
|
||||
|
||||
The word "its" (possesive) vs. "it's" (colloquial for "it is" or "it has")
|
||||
seems to confuse non-native (and some native) English speakers.
|
||||
It is better to donate the extra keystrokes and write "it is" or "it has".
|
||||
Any remaining "it's" are likely an incorrect spelling of "its".
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user