Skip to content

Good practice #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions talk/basicconcepts/assert.tex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

\begin{frame}[fragile]
\frametitlecpp[98]{Assertions}
\begin{block}{Good practices}
\begin{goodpractice}{Assert}
\begin{itemize}
\item Assertions are mostly for developers and debugging
\item Use them to check important invariants of your program
Expand All @@ -48,7 +48,7 @@
\item Decide if you want to disable them when you release code
\end{itemize}
\end{itemize}
\end{block}
\end{goodpractice}
\begin{exampleblock}{Disabling assertions}
\small
Compile a program with NDEBUG defined:\\
Expand Down
4 changes: 2 additions & 2 deletions talk/basicconcepts/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@
\begin{frame}[fragile]
\frametitlecpp[98]{Functions: good practices}
\begin{onlyenv}<1>
\begin{block}{Ensure good readability/maintainability:}
\begin{goodpractice}{Write readable functions}
\begin{itemize}
\item Keep functions short
\item Do one logical thing (single-responsibility principle)
\item Use expressive names
\item Document non-trivial functions
\end{itemize}
\end{block}
\end{goodpractice}
\begin{exampleblock}{Example: Good}
\begin{cppcode*}{gobble=2}
/// Count number of dilepton events in data.
Expand Down
4 changes: 2 additions & 2 deletions talk/basicconcepts/references.tex
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
\end{itemize}
\end{block}
\pause
\begin{alertblock}{Good practice}
\begin{goodpractice}{References}
\begin{itemize}
\item Always use references when you can
\item Consider that a reference will be modified
\item Use constness when it's not the case
\end{itemize}
\end{alertblock}
\end{goodpractice}
\end{frame}
7 changes: 6 additions & 1 deletion talk/basicconcepts/scopesnamespaces.tex
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@
\begin{itemize}
\item Variables are (statically) allocated when defined
\item Variables are freed at the end of a scope
\item Good practice: initialise variables when allocating them!
\end{itemize}
\end{block}
\begin{goodpractice}{Initialisation}
\begin{itemize}
\item Initialise variables when allocating them!
\item This prevents bugs reading uninitialised memory
\end{itemize}
\end{goodpractice}
\begin{multicols}{2}
\begin{overprint}[\columnwidth]
\onslide<1>
Expand Down
4 changes: 2 additions & 2 deletions talk/concurrency/mutexes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@

\begin{frame}[fragile]
\frametitlecpp[17]{Mutexes and Locks}
\begin{block}{Good practice}
\begin{goodpractice}{Locking}
\begin{itemize}
\item Generally, use \mintinline{cpp}{std::scoped_lock}. Before \cpp17 use \mintinline{cpp}{std::lock_guard}.
\item Hold as short as possible, consider wrapping critical section in block statement \mintinline{cpp}|{ }|
\item Only if manual control needed, use \mintinline{cpp}{std::unique_lock}
\end{itemize}
\end{block}
\end{goodpractice}
\begin{exampleblock}{}
\begin{cppcode*}{gobble=2}
void function(...) {
Expand Down
4 changes: 2 additions & 2 deletions talk/expert/sfinae.tex
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@
}
\end{cppcode*}
\end{block}
\begin{exampleblock}{Best practice}
\begin{goodpractice}{SFINAE vs.\ if constexpr}
\begin{itemize}
\item \mintinline{cpp}{if constexpr} can replace SFINAE in many places.
\item It is usually more readable as well. Use it if you can.
\end{itemize}
\end{exampleblock}
\end{goodpractice}
\end{frame}
4 changes: 2 additions & 2 deletions talk/morelanguage/initialization.tex
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@

\begin{frame}[fragile]
\frametitlecpp[11]{Initialization}
\begin{exampleblock}{Best practices}
\begin{goodpractice}{Initialization}
\begin{itemize}
\item In generic code, for a generic type \mintinline{cpp}{T}:
\begin{itemize}
Expand All @@ -166,7 +166,7 @@
\end{itemize}
\item Aggregates are very flexible. If your class does not need special initialization, make it an aggregate (rule of zero)
\end{itemize}
\end{exampleblock}
\end{goodpractice}
\end{frame}

\begin{frame}[fragile]
Expand Down
4 changes: 2 additions & 2 deletions talk/objectorientation/advancedoo.tex
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@
p->draw();
delete p; // dynamic dispatch to right destructor
\end{cppcode}
\begin{exampleblock}{Best practice}
\begin{goodpractice}{Virtual destructors}
\begin{itemize}
\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}
\end{itemize}
\end{exampleblock}
\end{goodpractice}
\end{frame}

\begin{frame}[fragile]
Expand Down
11 changes: 11 additions & 0 deletions talk/setup.tex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
\end{beamercolorbox}%
}

\setbeamercolor{goodpractice head}{fg=white,bg=orange!85!black}
\setbeamercolor{goodpractice body}{fg=black,bg=orange!25}

%%%%%%%%%%%%
% packages %
%%%%%%%%%%%%
Expand Down Expand Up @@ -84,6 +87,14 @@
\newcommand{\deprecated}{\textcolor{red}{\bf Deprecated}}
\newcommand{\removed}{\textcolor{red}{\bf Removed}}

\newenvironment{goodpractice}[1]
{%
\begin{beamerboxesrounded}[upper=goodpractice head,lower=goodpractice body,shadow=true]{Good practice: #1}
}%
{%
\end{beamerboxesrounded}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% frametitle with C++ version %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down