aboutsummaryrefslogtreecommitdiff
path: root/docs/styleguide-cpp.tex
blob: c606d37fd69766780f63b2a44d165990ba18c2a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
\documentclass{article}
\usepackage[colorlinks = true, urlcolor = blue, linkcolor = blue]{hyperref}
\usepackage{multirow}


%Setup for code snippets
\usepackage{listings}
\usepackage{xcolor}
\definecolor{darkGreen}{RGB}{63,127,95}
\lstset {
   language=C++,
   backgroundcolor=\color{black!3},
   basicstyle=\footnotesize,
   basicstyle=\ttfamily,
   keywordstyle=\color{blue}\ttfamily,
   stringstyle=\color{red}\ttfamily,
   commentstyle=\color{darkGreen}\ttfamily,
   morecomment=[l][\color{magenta}]{\#}
}

\usepackage{helvet}
\renewcommand{\rmdefault}{\sfdefault} %Use sans-serif font family


\title{OpenVic2 C++ Style Guidelines (Draft)}
\author{ZincLadder}
\date{\today\\v0.0.1}




\begin{document}
%=====================================

\maketitle
\tableofcontents
\clearpage

\section{Why Style?}
You may be wondering "Why do we need a style guide?" "Are you trying to give me homework?"

\subsection{General Principles}
\begin{itemize}
   \item Prefer clarity over brevity
   \item Don't optimize prematurely
   \item Avoid C-style casts
\end{itemize}

\subsection{File Formatting}
Source code files should adhere to the following:
\begin{itemize}
   \item Encoded in UTF-8
   \item Use tabs for indentation
   \item Use LF for end-of-line sequences
   \item Not have any trailing whitespace (Lines which end in spaces or tabs)
   \item Any \#include directives should be at the top of the file
\end{itemize}


\section{Conventions}
\subsection{Naming Conventions}

\begin{table}[!ht]
   \begin{center}
      \caption{Basic Naming Conventions}
   \begin{tabular}{|l|l|l|}
      \hline
      \bf Item & \bf Writing Convention & \bf Example \\
      \hline
      Class and Struct Names                   & PascalCase           & MyCoolExample \\
      Variables and Function Names             & CamelCase            & myCoolExample \\
      Constants, Enum Values, and Preprocessor & SnakeCase (all-caps) & MY\_COOL\_EXAMPLE \\
      Type aliases                             & SnakeCase (lower)    & my\_cool\_example\_t \\
      \hline
   \end{tabular}
   \end{center}
\end{table}

\begin{lstlisting}
#pragma once
#include<stdio.h>
#include<iostream>
// A comment
constexpr size_t UNIQUE_RGB_COLOURS = 256 * 256 * 256;

struct RGBColour {
   unsigned char r;
   unsigned char g;
   unsigned char b;
};

bool isColourGreyscale(RGBColour c);

class Something {

};
\end{lstlisting}

%=====================================
\end{document}