Skip to content
Merged
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
41 changes: 41 additions & 0 deletions SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,47 @@ \section{Increment/decrement Operators}
\normalsize


\section{Trailing Return Types}
\label{sec:TrailingReturnTypes}

Whenever choosing between a trailing return type (as introduced with C++11) and
the old form of having the return type before the function name (as was already
supported by C++98), prefer the form that is the shortest, and the simplest.
Copy link
Copy Markdown
Member

@jhlegarreta jhlegarreta Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer avoiding the "simplest" and "shortest" terms/would prefer a clear/objective rule: e.g. when using language built-in types, use the return type before the function name.

A few reasons:

  • I do not think contributors will be computing the length of the added characters/saying language built-in types is more clear IMO
  • If the ITK PR was done automatically using a regex, the rules of that regex should apply here (i.e. there was no explicit modelling of "shortest"/"simplest").


In the following example, the old form is preferred over a trailing return type:
\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
// Preferred:
template <typename T1, typename T2>
bool
AlmostEquals(T1 x1, T2 x2)

// Rather than:
template <typename T1, typename T2>
auto
AlmostEquals(T1 x1, T2 x2) -> bool
\end{minted}
\normalsize

In the following example, a trailing return type is preferred over the old form:

\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}

// Preferred:
template <typename TValue, unsigned int VLength>
auto
FixedArray<TValue, VLength>::Size() const -> SizeType

// Rather than:
template <typename TValue, unsigned int VLength>
typename FixedArray<TValue, VLength>::SizeType
FixedArray<TValue, VLength>::Size() const

\end{minted}
\normalsize


\section{Empty Arguments in Methods}
\label{sec:EmptyArgumentInMethods}

Expand Down