Skip to content

Commit aac3692

Browse files
author
Ruben Schmidmeister
authored
Merge branch 'master' into remove-glossary
2 parents 5e29d2e + a4e48b8 commit aac3692

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

documentation/src/basic-constructs.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ Multiple expressions or statements in one line increase the mental burden while
77
## Prefer logical operators to if statements
88

99
```csharp
10-
if (node.GetParenthesis(key)) {
10+
if (node.GetParenthesis(key))
11+
{
1112
item.Setting = false;
12-
} else {
13+
}
14+
else
15+
{
1316
item.Setting = true;
1417
}
1518
```
@@ -29,24 +32,28 @@ The condition of the if-statement should have no side effects.
2932
Avoid nested if-statements and prefer logical operators.
3033

3134
```csharp
32-
if (!Move(id)) {
35+
if (!Move(id))
36+
{
3337
return false;
3438
}
3539

36-
if (!UpdateStart(StartValue)) {
40+
if (!UpdateStart(StartValue))
41+
{
3742
return false;
3843
}
3944
```
4045
*Avoid side-effects*
4146

4247
```csharp
4348
var itemFound = Move(id);
44-
if (!itemFound) {
49+
if (!itemFound)
50+
{
4551
return false;
4652
}
4753

4854
var updateIsReady = UpdateStart(StateDelete);
49-
if (!updateIsReady) {
55+
if (!updateIsReady)
56+
{
5057
return false;
5158
}
5259
```
@@ -101,7 +108,8 @@ Avoid for-loops and use LINQ and higher order functions as an alternative.
101108
Whenever you are iterating over some kind of enumerator, prefer the foreach syntax:
102109

103110
```csharp
104-
foreach (var value in values.OrderByDescending(v => v)) {
111+
foreach (var value in values.OrderByDescending(v => v))
112+
{
105113
// Do something in reverse order
106114
}
107115
```

documentation/src/comments.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ Try to document your public interface.
2323

2424
```csharp
2525
/// <summary>
26-
/// Disconnects a previously connected slot
26+
/// Specifies that <see cref="Open"/> should open an existing file.
27+
/// When the file is opened, it should be truncated so that its size is zero bytes.
28+
/// Requires that <see cref="Write"/> is called too.
29+
/// Can not be used to together with <see cref="Append"/>.
2730
/// </summary>
28-
/// <param name="slotId">id of the slot</param>
29-
void Disconnect(int slotId);
31+
IFileOpeningBuilder Truncate(bool truncate = true);
3032
```
3133
*Commenting a function*
3234

documentation/src/naming.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ We do not use abbreviations that are ambiguous or unfamiliar to readers outside
2828
All abbreviations are written in PascalCase.
2929

3030
```csharp
31-
class JsonToHtmlConverter {}
32-
class IpAddress {}
33-
class UserId {}
34-
class TfsConnector {}
31+
class JsonToHtmlConverter
32+
{
33+
}
34+
class IpAddress
35+
{
36+
}
37+
class UserId
38+
{
39+
}
40+
class TfsConnector
41+
{
42+
}
3543
```
3644
*Abbrevation Examples*
3745

@@ -80,7 +88,8 @@ Table following table gives you the rules for each identifier.
8088
When dealing with UI Elements like buttons, combo boxes, grids, text boxes, etc. we append the full name of the type without any prefix to the variable name.
8189

8290
```csharp
83-
class UserRightDialog {
91+
class UserRightDialog
92+
{
8493
Grid _userGrid;
8594
Edit _userNameEdit;
8695
Button _okButton;

documentation/src/oop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If the library you are using do not offer their own abstractions, create a facad
1515
Avoid the usage of new, either inject types through the constructor or use factories to create objects on runtime. All Factories should be declared via a delegate in the form of:
1616

1717
```csharp
18-
public delegate ReturnValue ReturnValueFactory(Parameters parameters)
18+
public delegate ReturnValue ReturnValueFactory(Parameters parameters);
1919
```
2020
*Signature of factories*
2121

documentation/src/types.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
C# has a strong typing system, take advantage of it. A strong type will help you a lot in refactoring, and the compiler will easily tell you that you are using the wrong parameter if you do not have a string type like a comma separated list instead of a strong collection like a vector of longs.
66

77
```csharp
8-
class Vector {
9-
int X;
10-
int Y;
11-
int Z;
8+
public sealed class Vector
9+
{
10+
public Vector(int x, int y, int z)
11+
{
12+
X = x;
13+
Y = y;
14+
Z = z;
15+
}
16+
17+
public int X { get; }
18+
public int Y { get; }
19+
public int Z { get; }
1220
}
1321

1422
Vector CrossProduct(Vector factor1, Vector factor2);
@@ -25,21 +33,22 @@ The idea behind the new type idiom is to have additional type information, even
2533
So even if you have a single integer, you can create a new type from your abstract concept.
2634

2735
```csharp
28-
class Years {
29-
Years(int years)
36+
public sealed class Years
37+
{
38+
public Years(int years)
3039
{
3140
Value = years;
3241
}
3342

34-
int Value { get; }
43+
public int Value { get; }
3544
}
3645
```
3746
*Declaring the new type Years*
3847

3948
In this case we have a time period in years. The constructor should be explicit, otherwise a Year object would be automatically constructed from a given integer. That way you need to be explicit when you call a function like this:
4049

4150
```csharp
42-
bool OldEnough(Years years)
51+
bool OldEnough(Years years);
4352
```
4453
*Use the new type*
4554

0 commit comments

Comments
 (0)