Difference between revisions of "Documentation/4.0/Developers/Style Guide/Cpp"

From Slicer Wiki
Jump to: navigation, search
(Created page with '[[Documentation/{{documentation/version}}/Developers|Developers Information]]← {{ambox | type = protection | image = 40px|alt=Work in progress | te…')
 
(Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Documentation/{{documentation/version}}/Developers|Developers Information]]←
+
<noinclude>{{documentation/versioncheck}}</noinclude>
 +
{{documentation/underconstruction}}
 +
 
 +
= Indentation =
 +
Configure your text editor to do VTK style indentation:
 +
* [http://www.vtk.org/Wiki/Elisp_Code_for_VTK-Style_C_Indentation Emacs]
 +
* [http://wiki.na-mic.org/Wiki/index.php/User:Pieper Vi/Vim]  
 +
* [http://www.vtk.org/Wiki/VTK_FAQ#How_do_I_get_my_C.2B.2B_code_editor_to_do_VTK-style_indentation.3F Visual Studio]
 +
 
 +
= Naming =
 +
* Local variable should start with a lower case.
 +
** For example:
 +
 
 +
void vtkSlicerSliceLogic::SetForegroundLayer(vtkSlicerSliceLayerLogic *ForegroundLayer) // wrong!
 +
 
 +
should be
 +
 
 +
void vtkSlicerSliceLogic::SetForegroundLayer(vtkSlicerSliceLayerLogic *foregroundLayer)
 +
 
 +
* Member variable should start with a capital letter, and in implementation should be used in conjunction with 'this->' convention
 +
** For example
 +
 
 +
class Node {
 +
  Object &Foo();
 +
  Object Bla;
 +
};
 +
Object& Node::Foo()
 +
{
 +
  return this->Bla;
 +
}
  
{{ambox
 
| type  = protection
 
| image = [[File:InProgress.png|40px|alt=Work in progress]]
 
| text  = Page under construction.
 
}}
 
  
 
= References =
 
= References =
 +
* https://secure.wikimedia.org/wikipedia/en/wiki/Indent_style#GNU_style
 +
* https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
  
 
= Tools =
 
= Tools =
 +
 +
* http://universalindent.sourceforge.net/
 +
* http://uncrustify.sourceforge.net/
 +
 +
 +
 +
 +
 +
{{ambox|text=
 +
Use common sense and BE CONSISTENT.
 +
 +
If you are editing code, take a few minutes to look at the code around you and determine its style.
 +
If they use spaces around their if clauses, you should, too.
 +
If their comments have little boxes of stars around them, make your comments have little boxes of stars around them too.
 +
 +
The point of having style guidelines is to have a common vocabulary of coding so people can concentrate on what you are saying, rather than on how you are saying it. We present global style rules here so people know the vocabulary. But local style is also important. If code you add to a file looks drastically different from the existing code around it, the discontinuity throws readers out of their rhythm when they go to read it. Try to avoid this.
 +
 +
OK, enough writing about writing code; the code itself is much more interesting. Have fun!
 +
 +
<i>Source: [https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml Google C++ Style Guide]</i>
 +
}}

Latest revision as of 07:31, 14 June 2013

Home < Documentation < 4.0 < Developers < Style Guide < Cpp


For the latest Slicer documentation, visit the read-the-docs.



Indentation

Configure your text editor to do VTK style indentation:

Naming

  • Local variable should start with a lower case.
    • For example:
void vtkSlicerSliceLogic::SetForegroundLayer(vtkSlicerSliceLayerLogic *ForegroundLayer) // wrong!

should be

void vtkSlicerSliceLogic::SetForegroundLayer(vtkSlicerSliceLayerLogic *foregroundLayer)
  • Member variable should start with a capital letter, and in implementation should be used in conjunction with 'this->' convention
    • For example
class Node {
  Object &Foo();
  Object Bla;
};
Object& Node::Foo()
{
  return this->Bla;
}


References

Tools