Coding Conventions¶
The SMTK source responsibility contains files that following 3 distinctive coding styles:
SMTK Coding Style which should be used for all files except for those in the smtk/extension directory
For any files found under the
smtk/extension/vtk
directory, the VTK Coding Conventions should be followed and can be found here. The reason for this is to facilitate migration of VTK functionality developed for SMTK into VTK if the opportunity arises.For any files found under the
smtk/extension/paraview
directory that start withvtk
should also follow the VTK Coding Conventions.For any files found under the
smtk/extension/paraview
directory that start withpq
can follow the Qt or SMTK Coding Conventions. The reason is that the two conventions are compatible with each other though the SMTK style is a bit more extensive.
SMTK Coding Style¶
The coding style is based on clang-format
(which is defined by the .clang-format
file in the top-level directory). SMTK’s software process is driven by this and will provide an option to reformat your code in cases where this base style is violated. T In addition to this base style, all files following this style must adhere to the following:
No tabs or trailing white-space are allowed.
Must be valid UTF-8.
All files should end with a single newline (i.e., it is an error to have a source file without a newline or having multiple newlines at its end).
Class names should be camel case, starting with an uppercase.
Class member variables should start with
m_
ors_
for per-instance or class-static variables, respectively. In the extremely rare case where you need to use a global variable, it should start withg_
.Class methods should be camel case starting with a lowercase character (except acronyms which should be all-uppercase).
Use shared pointers and a static
create()
method for classes that own significant storage or must be passed by reference to their superclass.In terms of setting and getting a property/member variable of a class, the following conventions are used
setFoo(...)
- sets a member variablem_foo
foo() const
- returns the value of member variablem_foo
When referencing a class method inside another method of the class, always reference it using
this
, so for example to callA::foo()
inA::bar(), you would use ``this->foo()
.SMTK does use namespaces; classes added to the repository should be embedded in the namespace that is appropriate. Typically the namespace reflects the directory where the class is located. Some examples are:
smtk::attribute
- for all Attribute Resource related classes and are found under thesmtk/attribute
directorysmtk::common
- for all general purpose classes and are found under thesmtk/common
directorysmtk::extension
- for all non-core classes - this would include extensions to Qt, VTK, and ParaView and are found under thesmtk/extension
directorysmtk::io
- for all I/O classes and are found under thesmtk/io
directory
All header files must be guarded and the guard name should include the namespace of the class for example smtk/attribute/Attribute.h
uses smtk_attribute_Attribute_h
as the guard name.
All .h
and .cxx
files must also include the following boiler plate:
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
This is required in order to pass the CopyrightStatement
test.