C++ style guide: Difference between revisions

Jump to navigation Jump to search
179 bytes removed ,  17 August 2016
(→‎Namespace: explain reasons why we don't indent namespace)
Line 23: Line 23:
=== Namespace ===
=== Namespace ===


All code should be in the octave namespace (this is an ongoing project, we
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
are still moving existing classes into namespaces but all new classes
should go somewhere into octave::).  There is 1 extra level for namespaces
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.
inside octave to be used with care, we don't want too many namespaces.
Ask before creating a new namespace.
Ask before creating a new namespace.


* Do not indent namespace. The reasons are:
* Indent namespaces as any other block. Emacs and other editors can do this automatically.
:* simpler diffs
:* no need to break lines that get 2 or 4 extra columns added to the beginning
:* having the opening brace of functions and classes in column 1
:* it may look weird on a small example, but most files will be enclosed in a single namespace anyway.
* Define namespace on the .cc files;
* Define namespace on the .cc files;
* Do not use "using X" directives;
* Do not use "using X" directives;
Line 39: Line 35:


{{Code|namespace style on a .h file|<pre>
{{Code|namespace style on a .h file|<pre>
// Note lack of indentation
// Note indentation
namespace octave
namespace octave
{
{
namespace math
  namespace math
{
  {
 
    class foo
class foo
    {
{
    public:
public:
      foo (...);
  foo (...);
    };
 
  }
};
 
}
}
}
</pre>}}
</pre>}}


{{Code|namespace style on a .cc file|<pre>
{{Code|namespace style on a .cc file|<pre>
// Note lack of indentation, and that functions are not defined
// Note indentation and that functions are not defined
// as "octave::math::foo:foo"
// as "octave::math::foo:foo"
namespace octave
namespace octave
{
{
namespace math
  namespace math
{
  {
 
    foo::foo (...)
foo::foo (...)
    {
{
      ...;
  ...;
    }
}
  }
 
};
 
}
}
}
</pre>}}
</pre>}}

Navigation menu