You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/appendices/development.rst
+38-17Lines changed: 38 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,18 @@
8
8
Development Guide
9
9
*****************
10
10
11
+
The agility, extensibility, and performance of Celeritas depend strongly on
12
+
software infrastructure and best practices. This appendix describes how to
13
+
modify and extend the codebase.
14
+
15
+
.. include:: ../../CONTRIBUTING.rst
16
+
17
+
18
+
Code development guidelines
19
+
===========================
20
+
21
+
These are a list of recommendations when writing new code.
11
22
12
-
Guiding principles
13
-
==================
14
23
15
24
Maximize encapsulation
16
25
----------------------
@@ -43,7 +52,7 @@ Applications:
43
52
Examples:
44
53
45
54
- Random number sampling: write a unit sphere sampling functor instead of
46
-
replicating a polar-to-cartesian transform in a thousand places.
55
+
replicating a polar-to-Cartesian transform in a thousand places.
47
56
- Cell IDs: Opaque IDs add type safety so that you can't accidentally convert a
48
57
cell identifier into a double or switch a cell and material ID. It also makes
49
58
code more readable of course.
@@ -52,23 +61,27 @@ Examples:
52
61
Maximize code reuse
53
62
-------------------
54
63
55
-
No explanation needed.
64
+
Duplicating code means potentially duplicating bugs, duplicating the amount of
65
+
work needed when refactoring, and missing optimizations.
56
66
57
67
58
68
Minimize compile time
59
69
---------------------
60
70
61
71
Code performance is important but so is developer time. When possible,
62
72
minimize the amount of code touched by NVCC. (NVCC's error output is also
63
-
rudimentary compared to modern clang/gcc, so that's another reason to prefer
73
+
rudimentary compared to modern clang/GCC, so that's another reason to prefer
64
74
them compiling your code.)
65
75
76
+
66
77
Prefer single-state classes
67
78
---------------------------
68
79
69
80
As much as possible, make classes "complete" and valid after calling the
70
-
constructor. Don't have a series of functions that have to be called in a
71
-
specific order to put the class in a workable state. (And when it is not possible, code must be put in place to automatically detect (and warn the developer) if the specific order is not respected).
81
+
constructor. Try to avoid "finalize" functions that have to be called in a
82
+
specific order to put the class in a workable state. If a finalize function
83
+
*is* used, implement assertions to detect and warn the developer if the
84
+
required order is not respected.
72
85
73
86
When a class has a single function (especially if you name that function
74
87
``operator()``), its usage is obvious. The reader also doesn't have to know
@@ -78,6 +91,7 @@ When you have a class that needs a lot of data to start in a valid state, use a
78
91
``struct`` of intuitive objects to pass the data to the class's constructor.
79
92
The constructor can do any necessary validation on the input data.
80
93
94
+
81
95
Learn from the pros
82
96
-------------------
83
97
@@ -97,9 +111,9 @@ Test thoroughly
97
111
Functions should use programmatic assertions whenever assumptions are made:
98
112
99
113
- Use the ``CELER_EXPECT(x)`` assertion macro to test preconditions about
100
-
incoming data or initial internal states
114
+
incoming data or initial internal states.
101
115
- Use ``CELER_ASSERT(x)`` to express an assumption internal to a function (e.g.,
102
-
"this index is not out of range of the array")
116
+
"this index is not out of range of the array").
103
117
- Use ``CELER_ENSURE(x)`` to mark expectations about data being returned from a
104
118
function and side effects resulting from the function.
105
119
@@ -118,6 +132,7 @@ Implementation detail classes (in the ``celeritas::detail`` namespace, in
118
132
testing the detail classes is a good way to simplify edge case testing compared
119
133
to testing the higher-level code.
120
134
135
+
121
136
Style guidelines
122
137
================
123
138
@@ -132,6 +147,8 @@ became the style standard for the GPU-enabled Monte Carlo code `Shift`_.
0 commit comments