Wiki

Clone wiki

PyCA / Coding_Conventions

Coding conventions in PyCA

Naming

  • Class names use upper CamelCase
  • Class member methods use lower camelCase
  • Top-level functions use upper CamelCase

Parameter Order

Functions representing mathematical operations should take parameters in the same order the expression would be written. Since our operations generally take the output as a parameter, this means output(s) should be the first parameter(s). For example, A = B + C would be represented by void Add(A, B, C), and F = G(H) would be void Apply(F,G,H)

Order of Operations

For arithmetic operations, the order of operations is left to right, with one exception: two groups of operators with an underscore separating them are calculated last. For example

Add_AddMulC(Image3D d_o, Image3D di, Image3D di1, Image3D di2, float c) ~ do = di + (di1+di2)*c

In-Code Documentation

C++ functions should be documented using a comment block just before the highest level function definition. For example

:::c++
/**
 * @brief Load image, given filename
 *
 * `filename` should refer to a file loadable by ITK, or a PNG
 */
void LoadImage(std::string filename);

These comments are converted to docstrings using make docstring before running make. If multiple such comments exist they get concatenated together to produce the overall docstring.

The @brief directive comes from doxygen, and is interpreted correctly by the doxygen to doctring script. Other doxygen tags, however, are not reinterpreted, and should be avoided. ReStructuredText is a lightweight markup language similar to markdown, which python uses for docstrings. Since ReST is very readable even unparsed, we should not avoid using it even in the C++ documentation.

Updated