Skip to content

Commit 9ace861

Browse files
committed
first version (in one blow) of c# conventions
1 parent b121e66 commit 9ace861

File tree

2 files changed

+233
-4
lines changed

2 files changed

+233
-4
lines changed

convention.tex

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
\documentclass[11pt,a4paper]{book}
2+
\usepackage[utf8]{inputenc}
3+
\usepackage[english]{babel}
4+
\usepackage{paralist}
5+
6+
\usepackage{doavoidnot}
7+
8+
\author{Gergő Balogh}
9+
\title{Code Convention}
10+
\begin{document}
11+
\maketitle
12+
13+
\chapter{C\#}
14+
15+
\section{Capitalization styles}
16+
\paragraph{Pascal case} The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. \verb|PascalCase|
17+
\paragraph{Camel case} The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. \verb|camelCase|
18+
\paragraph{Uppercase} All letters in the identifier are capitalized. \verb|UPPERCASE|
19+
20+
\section{Naming}
21+
22+
\domark Use pascal case if the visibility of entity is public.
23+
\begin{verbatim}
24+
public
25+
void Something()
26+
\end{verbatim}
27+
28+
\domark Use camel case if the visibility of method, attribute, property or event is non-public.
29+
\begin{verbatim}
30+
private
31+
void something()
32+
33+
internal
34+
void something()
35+
\end{verbatim}
36+
37+
\domark Use camel case and start the identifier with an underscore (\_) if the visibility of variable is local.
38+
\begin{verbatim}
39+
internal
40+
void something()
41+
{
42+
int _count;
43+
}
44+
\end{verbatim}
45+
46+
\whymark You can use code completion to quickly list all local variables, just type the underscore sing (\_).
47+
48+
\domark Use camel case and start the name of parameters of lambda expressions with an underscore (\_).
49+
\begin{verbatim}
50+
var foo = ( _a, _b ) => _a + _b;
51+
\end{verbatim}
52+
53+
\domark Use pascal case in the name of namespaces, classes, interfaces, structures, enumerations and members of enumerations.
54+
55+
\domark Start name of interfaces with a capital I.
56+
57+
\domark Start name of generic type parameters with a capital T.
58+
\begin{verbatim}
59+
class ExampleClass< TValue >
60+
61+
interface IExampleInterface
62+
63+
enum ExampleEnum
64+
65+
struct ExampleStruct
66+
\end{verbatim}
67+
68+
\domark Use camel case in the name of parameters of methods.
69+
\begin{verbatim}
70+
void Somthing( int somethingToRead )
71+
\end{verbatim}
72+
73+
\notmark Do not use Hungarian notion.
74+
\begin{verbatim}
75+
int i_foo;
76+
float f_foo;
77+
\end{verbatim}
78+
79+
\avoidmark Avoid uncommon abbreviation. Use abbreviation, when you have no other choice.
80+
\begin{verbatim}
81+
string Idkwit = "true"; //I Don't Know What Is This
82+
\end{verbatim}
83+
84+
\domark Use the same case as in their first letter of abbreviation less then three character long.
85+
\begin{verbatim}
86+
private
87+
void uiReader()
88+
89+
private
90+
void readerUI()
91+
92+
public
93+
void UIReader()
94+
\end{verbatim}
95+
96+
\domark Use camel case in abbreviation more then two letters long.
97+
\begin{verbatim}
98+
private
99+
void umlReader()
100+
101+
public
102+
void UmlReader()
103+
\end{verbatim}
104+
105+
\avoidmark Avoid the using the following words, because they are too general to provide useful information.
106+
\begin{compactitem}
107+
\item data
108+
\item information
109+
\item some
110+
\item do
111+
\item make
112+
\end{compactitem}
113+
114+
\notmark Do not use plural form in the name of namespaces, classes, interfaces, structures, enumerations and members of enumerations.
115+
\begin{verbatim}
116+
items
117+
men
118+
\end{verbatim}
119+
120+
\notmark Do not put spaces inside empty parentheses.
121+
122+
\section{Layout}
123+
124+
\avoidmark Avoid lines longer then 80 characters. Prefer shorter lines as much as possible.
125+
126+
\subsection{Horizontal spacing}
127+
128+
\domark Use spaces at the inner side of all parentheses, except curly braces.
129+
\begin{verbatim}
130+
( Something< int >( _foo[ bla ] ) ) * 10
131+
\end{verbatim}
132+
133+
\domark Use spaces around operators, except parentheses, point (.), increment (\verb|++|) and decrement (\verb|--|) operators.
134+
\begin{verbatim}
135+
int foo = ( ( x == 0 ) ? ( z + 3 ) : bar.some[ 42 ] )
136+
foo++;
137+
\end{verbatim}
138+
139+
\domark Use tabs instead of spaces at the beginning of the line.
140+
141+
\notmark Do not mix tabs and spaces at the beginning of the line.
142+
143+
\domark Only increment the indentation level one-by-one.
144+
145+
\subsection{Line-breaks}
146+
147+
\domark Put curly braces in their own empty lines.
148+
\begin{verbatim}
149+
void foo()
150+
{
151+
if( true )
152+
{
153+
bla++;
154+
}
155+
}
156+
\end{verbatim}
157+
158+
\domark Put member modifiers in a separate line.
159+
\begin{verbatim}
160+
public static
161+
void Something()
162+
163+
private
164+
int count;
165+
\end{verbatim}
166+
167+
\domark Write getter and setter with one or no modifier in the same line with the name of auto property.
168+
\begin{verbatim}
169+
public
170+
int Count{ get; private set; }
171+
\end{verbatim}
172+
173+
\domark If necessary break line after equal sign (=).
174+
\begin{verbatim}
175+
int _count =
176+
x + 567567563 / 2121231 + foobar;
177+
\end{verbatim}
178+
179+
\domark If necessary break line before operators, except parentheses.
180+
\begin{verbatim}
181+
string _text =
182+
"this is a long string need to be"
183+
+ "broken into seperate lines";
184+
185+
"to write something"
186+
.Let().TaggedAsInformation()
187+
.Write();
188+
\end{verbatim}
189+
190+
\domark Put the closing parentheses in the same line with the last parameter, except curly braces.
191+
192+
\domark If necessary prefer to start method calls in a new line.
193+
194+
\domark Put all or none of the parameters into separate lines.
195+
\begin{verbatim}
196+
int count =
197+
AvarageOf(
198+
foo,
199+
bar,
200+
asd );
201+
\end{verbatim}
202+
203+
\subsection{Vertical spaces}
204+
205+
\notmark Do not put empty line around opening parentheses.
206+
207+
\domark Separate members in classes with an empty lines.
208+
\begin{verbatim}
209+
private
210+
int foo
211+
212+
public
213+
void Something()
214+
\end{verbatim}
215+
216+
\section{Commenting}
217+
218+
\domark Prefer documenting comments (///) over general one (//).
219+
220+
\notmark Do not use block comments (/* */).
221+
222+
\end{document}

texmf/tex/latex/doavoidnot/doavoidnot.sty

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
\setlength{\fboxrule}{1pt}
77
\setlength{\parindent}{0pt}
8+
\setlength{\parskip}{0pt}
89

910
\definecolor{notfg}{RGB}{217,39,39}
1011
\definecolor{notbg}{RGB}{255,149,149}
@@ -15,11 +16,17 @@
1516
\definecolor{dofg}{RGB}{91,184,47}
1617
\definecolor{dobg}{RGB}{181,255,137}
1718

18-
\newcommand{\domark}{\marginpar{\raggedleft\fcolorbox{dofg}{dobg}{\textcolor{dofg}{\textsf{\textbf{do}}}}}}
19-
\newcommand{\avoidmark}{\marginpar{\raggedleft\fcolorbox{avoidfg}{avoidbg}{\textcolor{avoidfg}{\textsf{\textbf{avoid}}}}}}
20-
\newcommand{\notmark}{\marginpar{\raggedleft\fcolorbox{notfg}{notbg}{\textcolor{notfg}{\textsf{\textbf{not}}}}}}
19+
\newcommand{\domark}{\fcolorbox{dofg}{dobg}{\textcolor{dofg}{\textsf{\textbf{do}}}}\hspace{1ex}}
20+
\newcommand{\avoidmark}{\fcolorbox{avoidfg}{avoidbg}{\textcolor{avoidfg}{\textsf{\textbf{avoid}}}}\hspace{1ex}}
21+
\newcommand{\notmark}{\fcolorbox{notfg}{notbg}{\textcolor{notfg}{\textsf{\textbf{not}}}}\hspace{1ex}}
22+
23+
\newcommand{\dommark}{\marginpar{\raggedleft\fcolorbox{dofg}{dobg}{\textcolor{dofg}{\textsf{\textbf{do}}}}}}
24+
\newcommand{\avoidmmark}{\marginpar{\raggedleft\fcolorbox{avoidfg}{avoidbg}{\textcolor{avoidfg}{\textsf{\textbf{avoid}}}}}}
25+
\newcommand{\notmmark}{\marginpar{\raggedleft\fcolorbox{notfg}{notbg}{\textcolor{notfg}{\textsf{\textbf{not}}}}}}
2126

2227
\definecolor{whyfg}{RGB}{0,134,131}
2328
\definecolor{whybg}{RGB}{103,255,255}
2429

25-
\newcommand{\whymark}{\marginpar{\raggedleft\fcolorbox{whyfg}{whybg}{\textcolor{whyfg}{\textsf{\textbf{why?}}}}}}
30+
\newcommand{\whymark}{\fcolorbox{whyfg}{whybg}{\textcolor{whyfg}{\textsf{\textbf{why?}}}}\hspace{1ex}}
31+
32+
\newcommand{\whymmark}{\marginpar{\raggedleft\fcolorbox{whyfg}{whybg}{\textcolor{whyfg}{\textsf{\textbf{why?}}}}}}

0 commit comments

Comments
 (0)