File tree 8 files changed +20
-15
lines changed
8 files changed +20
-15
lines changed Original file line number Diff line number Diff line change 37
37
38
38
\begin {frame }[fragile]
39
39
\frametitlecpp [98]{Assertions}
40
- \begin {block }{Good practices }
40
+ \begin {goodpractice }{Assert }
41
41
\begin {itemize }
42
42
\item Assertions are mostly for developers and debugging
43
43
\item Use them to check important invariants of your program
48
48
\item Decide if you want to disable them when you release code
49
49
\end {itemize }
50
50
\end {itemize }
51
- \end {block }
51
+ \end {goodpractice }
52
52
\begin {exampleblock }{Disabling assertions}
53
53
\small
54
54
Compile a program with NDEBUG defined:\\
Original file line number Diff line number Diff line change 216
216
\begin {frame }[fragile]
217
217
\frametitlecpp [98]{Functions: good practices}
218
218
\begin {onlyenv }<1>
219
- \begin {block }{Ensure good readability/maintainability: }
219
+ \begin {goodpractice }{Write readable functions }
220
220
\begin {itemize }
221
221
\item Keep functions short
222
222
\item Do one logical thing (single-responsibility principle)
223
223
\item Use expressive names
224
224
\item Document non-trivial functions
225
225
\end {itemize }
226
- \end {block }
226
+ \end {goodpractice }
227
227
\begin {exampleblock }{Example: Good}
228
228
\begin {cppcode* }{gobble=2}
229
229
/// Count number of dilepton events in data.
Original file line number Diff line number Diff line change 42
42
\end {itemize }
43
43
\end {block }
44
44
\pause
45
- \begin {alertblock }{Good practice }
45
+ \begin {goodpractice }{References }
46
46
\begin {itemize }
47
47
\item Always use references when you can
48
48
\item Consider that a reference will be modified
49
49
\item Use constness when it's not the case
50
50
\end {itemize }
51
- \end {alertblock }
51
+ \end {goodpractice }
52
52
\end {frame }
Original file line number Diff line number Diff line change 36
36
\begin {itemize }
37
37
\item Variables are (statically) allocated when defined
38
38
\item Variables are freed at the end of a scope
39
- \item Good practice: initialise variables when allocating them!
40
39
\end {itemize }
41
40
\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 }
42
47
\begin {multicols }{2}
43
48
\begin {overprint }[\columnwidth ]
44
49
\onslide <1>
Original file line number Diff line number Diff line change 112
112
113
113
\begin {frame }[fragile]
114
114
\frametitlecpp [17]{Mutexes and Locks}
115
- \begin {block }{Good practice }
115
+ \begin {goodpractice }{Locking }
116
116
\begin {itemize }
117
117
\item Generally, use \mintinline {cpp}{std::scoped_lock}. Before \cpp 17 use \mintinline {cpp}{std::lock_guard}.
118
118
\item Hold as short as possible, consider wrapping critical section in block statement \mintinline {cpp}|{ }|
119
119
\item Only if manual control needed, use \mintinline {cpp}{std::unique_lock}
120
120
\end {itemize }
121
- \end {block }
121
+ \end {goodpractice }
122
122
\begin {exampleblock }{}
123
123
\begin {cppcode* }{gobble=2}
124
124
void function(...) {
Original file line number Diff line number Diff line change 278
278
}
279
279
\end {cppcode* }
280
280
\end {block }
281
- \begin {exampleblock }{Best practice }
281
+ \begin {goodpractice }{SFINAE vs. \ if constexpr }
282
282
\begin {itemize }
283
283
\item \mintinline {cpp}{if constexpr} can replace SFINAE in many places.
284
284
\item It is usually more readable as well. Use it if you can.
285
285
\end {itemize }
286
- \end {exampleblock }
286
+ \end {goodpractice }
287
287
\end {frame }
Original file line number Diff line number Diff line change 147
147
148
148
\begin {frame }[fragile]
149
149
\frametitlecpp [11]{Initialization}
150
- \begin {exampleblock }{Best practices }
150
+ \begin {goodpractice }{Initialization }
151
151
\begin {itemize }
152
152
\item In generic code, for a generic type \mintinline {cpp}{T}:
153
153
\begin {itemize }
166
166
\end {itemize }
167
167
\item Aggregates are very flexible. If your class does not need special initialization, make it an aggregate (rule of zero)
168
168
\end {itemize }
169
- \end {exampleblock }
169
+ \end {goodpractice }
170
170
\end {frame }
171
171
172
172
\begin {frame }[fragile]
Original file line number Diff line number Diff line change 359
359
p->draw();
360
360
delete p; // dynamic dispatch to right destructor
361
361
\end {cppcode }
362
- \begin {exampleblock }{Best practice }
362
+ \begin {goodpractice }{Virtual destructors }
363
363
\begin {itemize }
364
364
\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}
365
365
\end {itemize }
366
- \end {exampleblock }
366
+ \end {goodpractice }
367
367
\end {frame }
368
368
369
369
\begin {frame }[fragile]
You can’t perform that action at this time.
0 commit comments