Skip to content

Commit 12fdf11

Browse files
committed
Coding style: clarify structure.
Move comparision rules from the "Readable code" section to the "Conditionals" one. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
1 parent 273ff2d commit 12fdf11

1 file changed

Lines changed: 50 additions & 50 deletions

File tree

docs/coding-style.md

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -59,56 +59,6 @@ if (a == 2) b = 5;
5959
```
6060
</div>
6161

62-
Use explicit comparison in equality operators:
63-
64-
```c
65-
void *p1, *p2;
66-
int i1, i2;
67-
char c1, c2;
68-
```
69-
70-
<div class="grid" markdown>
71-
```c title="Right"
72-
if (p1 != NULL)
73-
if (p2 == NULL)
74-
75-
if (i1 != 0)
76-
if (i2 == 0)
77-
78-
if (c1 != '\0')
79-
if (c2 == '\0')
80-
```
81-
82-
```c title="Wrong"
83-
if (p1)
84-
if (!p2)
85-
86-
if (i1)
87-
if (!i2)
88-
89-
if (c1)
90-
if (!c2)
91-
```
92-
</div>
93-
94-
Do not check boolean values for equality:
95-
96-
```c
97-
gboolean b1, b2;
98-
```
99-
100-
<div class="grid" markdown>
101-
```c title="Right"
102-
if (b1)
103-
if (!b2)
104-
```
105-
106-
```c title="Wrong"
107-
if (b1 == TRUE)
108-
if (b2 == FALSE)
109-
```
110-
</div>
111-
11262
## Comments
11363

11464
Precede comments with a blank line. If the comment belongs directly to the following code, there should not be a blank line after the comment, unless the comment contains a summary of several blocks of following code.
@@ -162,6 +112,56 @@ if (0 == i)
162112
```
163113
</div>
164114

115+
Use explicit comparison in equality operators:
116+
117+
```c
118+
void *p1, *p2;
119+
int i1, i2;
120+
char c1, c2;
121+
```
122+
123+
<div class="grid" markdown>
124+
```c title="Right"
125+
if (p1 != NULL)
126+
if (p2 == NULL)
127+
128+
if (i1 != 0)
129+
if (i2 == 0)
130+
131+
if (c1 != '\0')
132+
if (c2 == '\0')
133+
```
134+
135+
```c title="Wrong"
136+
if (p1)
137+
if (!p2)
138+
139+
if (i1)
140+
if (!i2)
141+
142+
if (c1)
143+
if (!c2)
144+
```
145+
</div>
146+
147+
Do not check boolean values for equality:
148+
149+
```c
150+
gboolean b1, b2;
151+
```
152+
153+
<div class="grid" markdown>
154+
```c title="Right"
155+
if (b1)
156+
if (!b2)
157+
```
158+
159+
```c title="Wrong"
160+
if (b1 == TRUE)
161+
if (b2 == FALSE)
162+
```
163+
</div>
164+
165165
## Function calls
166166

167167
Always include a space between the name and the left parentheses when calling functions:

0 commit comments

Comments
 (0)