Editing C++ style guide
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 25: | Line 25: | ||
The braces should not be indented, i.e., they align at the same indentation level as the keyword such as {{codeline|class}}. | The braces should not be indented, i.e., they align at the same indentation level as the keyword such as {{codeline|class}}. | ||
The body of the block is | The body of the block is indented. | ||
Example: | Example: | ||
Line 64: | Line 62: | ||
If you have nested {{codeline|if}} statements, use extra braces for extra clarification. | If you have nested {{codeline|if}} statements, use extra braces for extra clarification. | ||
==== Split long expressions ==== | ==== Split long expressions ==== | ||
Line 169: | Line 133: | ||
=== Namespace === | === Namespace === | ||
All code should be in the | All code should be in the octave namespace. This is an ongoing project. We | ||
are still moving existing classes into namespaces but all new classes | |||
should go somewhere into the "octave" namespace. There is 1 extra level for namespaces | |||
inside octave to be used with care, we don't want too many namespaces. | |||
Ask before creating a new namespace. | |||
* Indent namespaces as any other block. Emacs and other editors can do this automatically. | |||
* Define namespace on the .cc files; | |||
* Do not use "using X" directives; | |||
* Do not declare anything on the std namespace; | |||
{{Code|namespace style on a .h file|<syntaxhighlight lang="cpp"> | |||
// Note indentation | |||
{{Code| | namespace octave | ||
{ | |||
namespace math | |||
{ | |||
class foo | |||
{ | |||
public: | |||
foo (...); | |||
}; | |||
} | |||
} | |||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
{{Code|namespace style on a .cc file|<syntaxhighlight lang="cpp"> | |||
// Note indentation and that functions are not defined | |||
{{Code| | // as "octave::math::foo:foo" | ||
// Note indentation and that functions are not defined as "octave::math::foo:foo" | |||
namespace octave | namespace octave | ||
{ | { | ||
Line 203: | Line 173: | ||
} | } | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
== Naming == | == Naming == | ||
Use lowercase names if possible. Uppercase is acceptable for variable names consisting of 1-2 letters. Do not use mixed case | Use lowercase names if possible. Uppercase is acceptable for variable | ||
names consisting of 1-2 letters. Do not use mixed case names. | |||
=== Member Variables === | === Member Variables === | ||
Line 296: | Line 263: | ||
|} | |} | ||
When passing variables that are large, but will not be changed in a subroutine (read-only), | When passing variables that are large, but will not be changed in a subroutine (read-only), consider using 'const' references. This helps avoid overflowing the finite stack capacity of a program while still ensuring that read-only access is enforced. | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 327: | Line 294: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||
=== std::string === | === std::string === |