This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
forked from RaiderRobotics5024/201718Main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RaiderRobotics FRC 5024 c-cpp coding conventions.rtf
103 lines (102 loc) · 13.4 KB
/
RaiderRobotics FRC 5024 c-cpp coding conventions.rtf
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
101
102
103
{\rtf1\ansi\deff0\adeflang1025
{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\fnil\fprq0\fcharset2 Symbol;}{\f4\fnil\fprq0\fcharset128 OpenSymbol{\*\falt Arial Unicode MS};}{\f5\fswiss\fprq2\fcharset128 Arial;}{\f6\fnil\fprq2\fcharset0 Microsoft YaHei;}{\f7\fnil\fprq2\fcharset0 SimSun;}{\f8\fnil\fprq0\fcharset128 Mangal;}{\f9\fnil\fprq2\fcharset0 Mangal;}}
{\colortbl;\red0\green0\blue0;\red0\green0\blue128;\red128\green128\blue128;}
{\stylesheet{\s0\snext0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033 Default;}
{\*\cs15\snext15\dbch\af4\loch\f3 WW8Num1z0;}
{\*\cs16\snext16\dbch\af4\loch\f4 WW8Num1z1;}
{\*\cs17\snext17 WW8Num2z0;}
{\*\cs18\snext18 WW8Num2z1;}
{\*\cs19\snext19 WW8Num2z2;}
{\*\cs20\snext20 WW8Num2z3;}
{\*\cs21\snext21 WW8Num2z4;}
{\*\cs22\snext22 WW8Num2z5;}
{\*\cs23\snext23 WW8Num2z6;}
{\*\cs24\snext24 WW8Num2z7;}
{\*\cs25\snext25 WW8Num2z8;}
{\*\cs26\snext26\hich\af4\dbch\af4\loch\f4 Bullets;}
{\*\cs27\snext27\cf2\ul\ulc0\langfe255\lang255\lang255 Internet Link;}
{\s28\sbasedon0\snext29\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb240\sa120\keepn\ltrpar\cf0\kerning1\hich\af6\langfe2052\dbch\af9\afs28\lang1081\loch\f2\fs28\lang1033 Heading;}
{\s29\sbasedon0\snext29\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb0\sa120\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033 Text body;}
{\s30\sbasedon29\snext30\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb0\sa120\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af8\afs24\lang1081\loch\f5\fs24\lang1033 List;}
{\s31\sbasedon0\snext31\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb120\sa120\noline\ltrpar\cf0\i\kerning1\hich\af7\langfe2052\dbch\af8\afs24\lang1081\ai\loch\f5\fs24\lang1033 Caption;}
{\s32\sbasedon0\snext32\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\noline\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af8\afs24\lang1081\loch\f5\fs24\lang1033 Index;}
}{\*\listtable{\list\listtemplateid1
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u61623 ?;}{\levelnumbers;}\f3\dbch\af4\fi-360\li720}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u9702 ?;}{\levelnumbers;}\f4\dbch\af4\fi-360\li1080}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u9642 ?;}{\levelnumbers;}\f4\dbch\af4\fi-360\li1440}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u61623 ?;}{\levelnumbers;}\f3\dbch\af4\fi-360\li1800}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u9702 ?;}{\levelnumbers;}\f4\dbch\af4\fi-360\li2160}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u9642 ?;}{\levelnumbers;}\f4\dbch\af4\fi-360\li2520}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u61623 ?;}{\levelnumbers;}\f3\dbch\af4\fi-360\li2880}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u9702 ?;}{\levelnumbers;}\f4\dbch\af4\fi-360\li3240}
{\listlevel\levelnfc23\leveljc0\levelstartat1\levelfollow0{\leveltext \'01\u9642 ?;}{\levelnumbers;}\f4\dbch\af4\fi-360\li3600}\listid1}
{\list\listtemplateid2
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-432\li432}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-576\li576}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-720\li720}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-864\li864}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-1008\li1008}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-1152\li1152}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-1296\li1296}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-1440\li1440}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow0{\leveltext \'00;}{\levelnumbers;}\fi-1584\li1584}\listid2}
}{\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}{\listoverride\listid2\listoverridecount0\ls2}}{\info{\author Michael Feeney}{\creatim\yr2018\mo2\dy10\hr8\min52}{\revtim\yr0\mo0\dy0\hr0\min0}{\printim\yr0\mo0\dy0\hr0\min0}{\comment OpenOffice}{\vern4150}}\deftab709
{\*\pgdsctbl
{\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 Default;}
{\pgdsc1\pgdscuse195\pgndec\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 First Page;}}
\formshade{\*\pgdscno0}\paperh15840\paperw12240\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\sectunlocked1\pgndec\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
\pgndec\pard\plain \s28\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb240\sa120\keepn\ltrpar\cf0\kerning1\hich\af6\langfe2052\dbch\af9\afs28\lang1081\loch\f2\fs28\lang1033\sb240\sa120\keepn{\rtlch \ltrch\loch
2018 FRC 5024 (Raider Robotics) C/C++ coding conventions:}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
These aren't \'81\'67hard and fast\'81\'68 rules, but if we keep things consistent, the code will be a easier to read. There's a number of interesting C/C++ conventions that are worth reading (ONLY if you are interested), like Valve's: }{{\field{\*\fldinst HYPERLINK "https://github.com/ValveSoftware/vogl/wiki/Coding-Conventions" }\*\cs27\cf2\ul\ulc0\langfe255\lang255\lang255\dbch\af5\rtlch \ltrch\loch
https://github.com/ValveSoftware/vogl/wiki/Coding-Conventions}{\dbch\af5\rtlch \ltrch\loch
}} and Google's: }{{\field{\*\fldinst HYPERLINK "https://google.github.io/styleguide/cppguide.html" }\*\cs27\cf2\ul\ulc0\langfe255\lang255\lang255\dbch\af5\rtlch \ltrch\loch
https://google.github.io/styleguide/cppguide.html}{\dbch\af5\rtlch \ltrch\loch
}} }
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
These are pretty standard for people who are actually making things. i.e. they aren't just \'81\'67adding the latest thing\'81\'68 just because it's \'81\'67the latest thing\'81\'68. }
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
Unlike many languages, the C++ standard body is made up of volunteers, almost all of them either compiler vendors or journalist, rather than \'81\'67steered\'81\'68 by an industry body or company \u8211\'3f so they tend to add things to the \'81\'67standard\'81\'68 that are \'81\'67neat\'81\'68, but that no one asked for. So the \'81\'67latest\'81\'68 C++ standards are barely used, is my point. }
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
Here's ours:}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\dbch\af5\rtlch \ltrch\loch
}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\rtlch \ltrch\loch
Use the Kernighan and Richie style for braces: brace on the }{\i\ai\rtlch \ltrch\loch
next }{\i0\ai0\rtlch \ltrch\loch
line, and on their own}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Use sensible variable and class names}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
For boolean (bool), add either a \'81\'67b\'81\'68 or \'81\'67is\'81\'68 at the beginning (so \'81\'67bEnabled\'81\'68 or \'81\'67isEnabled\'81\'68)}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Use a variation of \'81\'67Camel Case\'81\'68 notation, so DriveSystemMotor or driveSystemMotor rather than drivesystemmotor or drive_system_motor}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Use ALL_CAPITOLS with an underscore between words for \'81\'67const\'81\'68 (constants)}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Is a \'81\'67p\'81\'68 before all pointer variables, eg. \'81\'67pDriveMotor\'81\'68}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Use the \'81\'67this pointer\'81\'68 inside any class methods, to clarify that it's a class scoped variable, so this->pDriveMotor rather than just pDriveMotor}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Use an explicit \'81\'67return\'81\'68 at the end of methods, even if they return void (nothing)}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Use nullptr or NULL for pointers that point to nothing (or haven't been initialized)}
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Initialize things in the constructor, not using the C++14 initialize list method. }
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
As a general rule, avoid C++11 (and beyond) conventions. If you're not sure, ask your programming mentors. }
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Don't use exceptions. Ever. }
\par \pard\plain \s0\ql\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ltrpar\cf0\kerning1\hich\af7\langfe2052\dbch\af9\afs24\lang1081\loch\f5\fs24\lang1033{\listtext\pard\plain \dbch\af4\loch\f3 \u61623\'3f\tab}\ilvl0\ls1 \li720\ri0\lin720\rin0\fi-360{\i0\ai0\rtlch \ltrch\loch
Only #include files you absolutely require. }
\par }