minimc 0.5.1
Loading...
Searching...
No Matches
Style Guide

Introduction

MiniMC primarily adheres to the Google C++ Style Guide for source code style. Cases which are not addressed in the Google C++ Style Guide are addressed individually here.

Function Names

Function names should generally begin with a verb describing what it does . For instance, class methods which sample a random distribution are prefixed with Sample.

Declaration Order

The declaration order provided in the Google C++ Style Guide is recommended. This section clarifies cases which are not explicitly mentioned therein.

Static Functions

Static functions (such as helper functions which do not access instance member variables) should be declared after class constants, followed by factory functions and class constructors.

Friends

friend declarations occur at the very beginning of a class declaration, before any access specifiers such as private, public, or protected.

Variable Assignments

There exist two ways to initialize variables: direct initialization and copy initialization :

// Direct (uniform) initialization
auto x{42};
// Copy initialization
auto x = 42;

Although both styles are totally valid, we prefer to use direct initialization as it avoids a potentially expensive copy operation in certain scenarios. Furthermore, we prefer to use uniform initialization's curly braces as it prevents narrowing conversions.

Of course, there will always be cases where copy initialization is simply clearer without the cost of an expensive copy (such as initializing a reference or copying an rvalue for which there is a move constructor) so the choice is ultimately up to an informed developer's discretion.

Documentation

  • Use the boldsymbol environment to denote vectors
  • Use the bmatrix environment for displaying matrices in documentation
\boldsymbol{p} =
\begin{bmatrix}
x \\ y \\ z
\end{bmatrix}

\[ \boldsymbol{p} = \begin{bmatrix} x \\ y \\ z \end{bmatrix} \]