-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvention.tex
More file actions
284 lines (213 loc) · 6.69 KB
/
Copy pathconvention.tex
File metadata and controls
284 lines (213 loc) · 6.69 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{paralist}
\usepackage{doavoidnot}
\author{Gergő Balogh}
\title{Code Convention}
\begin{document}
\maketitle
\chapter{C\#}
\section{Capitalization styles}
\paragraph{Pascal case} The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. \verb|PascalCase|
\paragraph{Camel case} The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. \verb|camelCase|
\paragraph{Uppercase} All letters in the identifier are capitalized. \verb|UPPERCASE|
\section{Naming}
\domark Use pascal case if the visibility of entity is public.
\begin{verbatim}
public
void Something()
\end{verbatim}
\domark Use camel case if the visibility of method, attribute, property or event is non-public.
\begin{verbatim}
private
void something()
internal
void something()
\end{verbatim}
\domark Use camel case and start the identifier with an underscore (\_) if the visibility of variable is local.
\begin{verbatim}
internal
void something()
{
int _count;
}
\end{verbatim}
\whymark You can use code completion to quickly list all local variables, just type the underscore sing (\_).
\domark Use camel case and start the name of parameters of lambda expressions with an underscore (\_).
\begin{verbatim}
var foo = ( _a, _b ) => _a + _b;
\end{verbatim}
\domark Use the variable name \_ (a single underscore) to denote variables in lambda expressions, which is irrelevant in the current context.
\begin{verbatim}
(_, _b) => _b + 1
\end{verbatim}
\domark Use pascal case in the name of namespaces, classes, interfaces, structures, enumerations and members of enumerations.
\domark Start name of interfaces with a capital I.
\domark Start name of generic type parameters with a capital T.
\begin{verbatim}
class ExampleClass< TValue >
interface IExampleInterface
enum ExampleEnum
struct ExampleStruct
\end{verbatim}
\domark Use camel case in the name of parameters of methods.
\begin{verbatim}
void Somthing( int somethingToRead )
\end{verbatim}
\notmark Do not use Hungarian notion.
\begin{verbatim}
int i_foo;
float f_foo;
\end{verbatim}
\whymark It usually results cryptic abbreviation and types are noted and shown by Visual Studio or any other IDE.
\avoidmark Avoid using single letter variable names.
\begin{verbatim}
//avoid
int a;
int b;
//do
int componentA;
int componentB;
\end{verbatim}
\notmark Do not mark member with m\_ prefix.
\begin{verbatim}
int m_length //wrong
int length //right
\end{verbatim}
\notmark Do not use white-spaces to construct columns in the source code.
\begin{verbatim}
//do
int length = 10;
string name = "Thangorodrim;
//wrong
int length = 10;
string name = "Thangorodrim;
\end{verbatim}
\whymark It suggest structures which do not exist.
\avoidmark Avoid uncommon abbreviation. Use abbreviation, when you have no other choice.
\begin{verbatim}
string Idkwit = "true"; //I Don't Know What Is This
\end{verbatim}
\domark Use the same case as in their first letter of abbreviation less then three character long.
\begin{verbatim}
private
void uiReader()
private
void readerUI()
public
void UIReader()
\end{verbatim}
\domark Use camel case in abbreviation more then two letters long.
\begin{verbatim}
private
void umlReader()
public
void UmlReader()
\end{verbatim}
\avoidmark Avoid the using the following words.
\begin{compactitem}
\item data
\item information
\item some
\item do
\item make
\end{compactitem}
\whymark Because they are too general to provide useful information.
\notmark Do not use plural form in the name of namespaces, classes, interfaces, structures, enumerations and members of enumerations.
\begin{verbatim}
//wrong
items
men
//right
itemCollection
manCollection
\end{verbatim}
\whymark It is easy to misread the plural and singular forms. Can not find irregular forms by searching singulars.
\section{Layout}
\avoidmark Avoid lines longer then 80 characters. Prefer shorter lines as much as possible.
\subsection{Horizontal spacing}
\notmark Do not put spaces inside empty parentheses.
\domark Use spaces at the inner side of all parentheses, except curly braces.
\begin{verbatim}
( Something< int >( _foo[ bla ] ) ) * 10
\end{verbatim}
\domark Use spaces around operators, except parentheses, point (.), increment (\verb|++|) and decrement (\verb|--|) operators.
\begin{verbatim}
int foo = ( ( x == 0 ) ? ( z + 3 ) : bar.some[ 42 ] )
foo++;
\end{verbatim}
\domark Use spaces instead of tabs at the beginning of the line.
\domark Use four spaces per each indentation level. 4 spaces = 1 tab
\notmark Do not mix tabs and spaces at the beginning of the line.
\domark Only increment the indentation level one-by-one.
\subsection{Line-breaks}
\domark Put curly braces in their own empty lines.
\begin{verbatim}
void foo()
{
if( true )
{
bla++;
}
}
\end{verbatim}
\domark Put member modifiers in a separate line.
\begin{verbatim}
public static
void Something()
private
int count;
\end{verbatim}
\domark Write getter and setter with one or no modifier in the same line with the name of auto property.
\begin{verbatim}
public
int Count{ get; private set; }
\end{verbatim}
\domark If necessary break line after equal sign (=).
\begin{verbatim}
int _count =
x + 567567563 / 2121231 + foobar;
\end{verbatim}
\domark If necessary break line before operators, except parentheses and assignment (=).
\begin{verbatim}
string _text =
"this is a long string need to be"
+ "broken into seperate lines";
"to write something"
.Let().TaggedAsInformation()
.Write();
\end{verbatim}
\domark Put the closing parentheses in the same line with the last parameter, except curly braces.
\begin{verbatim}
int grantPermissions(
string user,
string password,
int id,
PersmissionSet permission )
\end{verbatim}
\domark If necessary prefer to start method calls in a new line.
\domark Put all or none of the parameters into separate lines.
\begin{verbatim}
int count =
AvarageOf(
foo,
bar,
asd );
\end{verbatim}
\subsection{Vertical spaces}
\domark Separate members in classes with an empty lines.
\begin{verbatim}
private
int foo
public
void Something()
\end{verbatim}
\section{Commenting}
\domark Prefer documenting comments (///) over general one (//).
\notmark Do not use block comments (/* */).
\appendix
\chapter{C\#}
\section{EditorConfig for Visual Studio}
For further details and \emph{some} automatic style and convention settings please use the \texttt{.editorcongif} file next to this document. It only contains Visual Studio and C\#{} specific settings. This file do not cover every details present in this documents and provided \emph{as is}.
\end{document}