Skip to content

Commit b2b20b0

Browse files
N-Dekkerhjmjohnson
authored andcommitted
DOC: Add guideline on using a backslash as line continuation character
Follow-up to ITK pull request InsightSoftwareConsortium/ITK#3713 commit InsightSoftwareConsortium/ITK@69151c3 "STYLE: Remove backslash + indent from literals, to avoid unwanted spaces"
1 parent 805704e commit b2b20b0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ \section{Overview}%
6262
argument lists.
6363
\item \textbf{Ternary Operator}: accepted standards for using the ternary
6464
operator.
65+
\item \textbf{Backslashes}: guideline on using a backslash as line continuation
66+
character.
6567
\item \textbf{Using Standard Macros} (itkMacro.h): use of standard macros in
6668
header files.
6769
\item \textbf{Exception Handling}: how to add exception handling to the system.
@@ -3258,6 +3260,43 @@ \section{Ternary Operator}%
32583260
And hence, the ternary operator is accepted in such cases.
32593261
32603262
3263+
\section{Backslashes}%
3264+
\label{sec:Backslashes}
3265+
3266+
The use of a backslash as line continuation character sometimes
3267+
hampers code readability. A backslash at the end of a line that has C++ \code{//}
3268+
comment may be quite confusing. For example, it may be overlooked easily that
3269+
the following code has commented out the \code{Sleep()} function call:
3270+
3271+
\small
3272+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
3273+
// Will we go to sleep or not? \
3274+
Sleep();
3275+
\end{minted}
3276+
\normalsize
3277+
3278+
The use of backslashes in a multiline string literal is
3279+
troublesome. For example, the following \code{badDescription} has all the space
3280+
characters of the indentation between \enquote{developers with } and \enquote{an extensive suite}
3281+
embedded inside the string, which may not be intended. The definition of
3282+
\code{goodDescription} shows how to define such a lengthy string properly (as
3283+
the compiler concatenates adjacent string literals automatically).
3284+
3285+
\small
3286+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
3287+
const char badDescription[] = "ITK is an open-source, cross-platform library that provides developers with \
3288+
an extensive suite of software tools for image analysis.";
3289+
//|||||||||||||||||||||||||||||||||<- 36 extra spaces included between "with" and "an" in sentence above
3290+
3291+
const char goodDescription[] = "ITK is an open-source, cross-platform library that provides developers with "
3292+
"an extensive suite of software tools for image analysis.";
3293+
\end{minted}
3294+
\normalsize
3295+
3296+
The use of a backslash as line continuation character is discouraged in standard C++ code blocks.
3297+
Backslashes are allowed when defining lengthy preprocessor macros to allow for
3298+
improved readability when they span multiple lines.
3299+
32613300
\section{Using Standard Macros}%
32623301
\label{sec:UsingStandardMacros}
32633302

0 commit comments

Comments
 (0)