File tree Expand file tree Collapse file tree 8 files changed +20
-15
lines changed
Expand file tree Collapse file tree 8 files changed +20
-15
lines changed Original file line number Diff line number Diff line change 3737
3838\begin {frame }[fragile]
3939 \frametitlecpp [98]{Assertions}
40- \begin {block }{Good practices }
40+ \begin {goodpractice }{Assert }
4141 \begin {itemize }
4242 \item Assertions are mostly for developers and debugging
4343 \item Use them to check important invariants of your program
4848 \item Decide if you want to disable them when you release code
4949 \end {itemize }
5050 \end {itemize }
51- \end {block }
51+ \end {goodpractice }
5252 \begin {exampleblock }{Disabling assertions}
5353 \small
5454 Compile a program with NDEBUG defined:\\
Original file line number Diff line number Diff line change 216216\begin {frame }[fragile]
217217 \frametitlecpp [98]{Functions: good practices}
218218 \begin {onlyenv }<1>
219- \begin {block }{Ensure good readability/maintainability: }
219+ \begin {goodpractice }{Write readable functions }
220220 \begin {itemize }
221221 \item Keep functions short
222222 \item Do one logical thing (single-responsibility principle)
223223 \item Use expressive names
224224 \item Document non-trivial functions
225225 \end {itemize }
226- \end {block }
226+ \end {goodpractice }
227227 \begin {exampleblock }{Example: Good}
228228 \begin {cppcode* }{gobble=2}
229229 /// Count number of dilepton events in data.
Original file line number Diff line number Diff line change 4242 \end {itemize }
4343 \end {block }
4444 \pause
45- \begin {alertblock }{Good practice }
45+ \begin {goodpractice }{References }
4646 \begin {itemize }
4747 \item Always use references when you can
4848 \item Consider that a reference will be modified
4949 \item Use constness when it's not the case
5050 \end {itemize }
51- \end {alertblock }
51+ \end {goodpractice }
5252\end {frame }
Original file line number Diff line number Diff line change 3636 \begin {itemize }
3737 \item Variables are (statically) allocated when defined
3838 \item Variables are freed at the end of a scope
39- \item Good practice: initialise variables when allocating them!
4039 \end {itemize }
4140 \end {block }
41+ \begin {goodpractice }{Initialisation}
42+ \begin {itemize }
43+ \item Initialise variables when allocating them!
44+ \item This prevents bugs reading uninitialised memory
45+ \end {itemize }
46+ \end {goodpractice }
4247 \begin {multicols }{2}
4348 \begin {overprint }[\columnwidth ]
4449 \onslide <1>
Original file line number Diff line number Diff line change 112112
113113\begin {frame }[fragile]
114114 \frametitlecpp [17]{Mutexes and Locks}
115- \begin {block }{Good practice }
115+ \begin {goodpractice }{Locking }
116116 \begin {itemize }
117117 \item Generally, use \mintinline {cpp}{std::scoped_lock}. Before \cpp 17 use \mintinline {cpp}{std::lock_guard}.
118118 \item Hold as short as possible, consider wrapping critical section in block statement \mintinline {cpp}|{ }|
119119 \item Only if manual control needed, use \mintinline {cpp}{std::unique_lock}
120120 \end {itemize }
121- \end {block }
121+ \end {goodpractice }
122122 \begin {exampleblock }{}
123123 \begin {cppcode* }{gobble=2}
124124 void function(...) {
Original file line number Diff line number Diff line change 278278 }
279279 \end {cppcode* }
280280 \end {block }
281- \begin {exampleblock }{Best practice }
281+ \begin {goodpractice }{SFINAE vs. \ if constexpr }
282282 \begin {itemize }
283283 \item \mintinline {cpp}{if constexpr} can replace SFINAE in many places.
284284 \item It is usually more readable as well. Use it if you can.
285285 \end {itemize }
286- \end {exampleblock }
286+ \end {goodpractice }
287287\end {frame }
Original file line number Diff line number Diff line change 147147
148148\begin {frame }[fragile]
149149 \frametitlecpp [11]{Initialization}
150- \begin {exampleblock }{Best practices }
150+ \begin {goodpractice }{Initialization }
151151 \begin {itemize }
152152 \item In generic code, for a generic type \mintinline {cpp}{T}:
153153 \begin {itemize }
166166 \end {itemize }
167167 \item Aggregates are very flexible. If your class does not need special initialization, make it an aggregate (rule of zero)
168168 \end {itemize }
169- \end {exampleblock }
169+ \end {goodpractice }
170170\end {frame }
171171
172172\begin {frame }[fragile]
Original file line number Diff line number Diff line change 359359 p->draw();
360360 delete p; // dynamic dispatch to right destructor
361361 \end {cppcode }
362- \begin {exampleblock }{Best practice }
362+ \begin {goodpractice }{Virtual destructors }
363363 \begin {itemize }
364364 \item If you expect users to inherit from your class and override methods (i.e.\ use your class polymorphically), declare its destructor \mintinline {cpp}{virtual}
365365 \end {itemize }
366- \end {exampleblock }
366+ \end {goodpractice }
367367\end {frame }
368368
369369\begin {frame }[fragile]
You can’t perform that action at this time.
0 commit comments