mirror of
https://github.com/MidnightCommander/website.git
synced 2026-02-02 11:13:47 -08:00
Coding style: clarify structure.
Move comparision rules from the "Readable code" section to the "Conditionals" one. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
@@ -59,56 +59,6 @@ if (a == 2) b = 5;
|
||||
```
|
||||
</div>
|
||||
|
||||
Use explicit comparison in equality operators:
|
||||
|
||||
```c
|
||||
void *p1, *p2;
|
||||
int i1, i2;
|
||||
char c1, c2;
|
||||
```
|
||||
|
||||
<div class="grid" markdown>
|
||||
```c title="Right"
|
||||
if (p1 != NULL)
|
||||
if (p2 == NULL)
|
||||
|
||||
if (i1 != 0)
|
||||
if (i2 == 0)
|
||||
|
||||
if (c1 != '\0')
|
||||
if (c2 == '\0')
|
||||
```
|
||||
|
||||
```c title="Wrong"
|
||||
if (p1)
|
||||
if (!p2)
|
||||
|
||||
if (i1)
|
||||
if (!i2)
|
||||
|
||||
if (c1)
|
||||
if (!c2)
|
||||
```
|
||||
</div>
|
||||
|
||||
Do not check boolean values for equality:
|
||||
|
||||
```c
|
||||
gboolean b1, b2;
|
||||
```
|
||||
|
||||
<div class="grid" markdown>
|
||||
```c title="Right"
|
||||
if (b1)
|
||||
if (!b2)
|
||||
```
|
||||
|
||||
```c title="Wrong"
|
||||
if (b1 == TRUE)
|
||||
if (b2 == FALSE)
|
||||
```
|
||||
</div>
|
||||
|
||||
## Comments
|
||||
|
||||
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)
|
||||
```
|
||||
</div>
|
||||
|
||||
Use explicit comparison in equality operators:
|
||||
|
||||
```c
|
||||
void *p1, *p2;
|
||||
int i1, i2;
|
||||
char c1, c2;
|
||||
```
|
||||
|
||||
<div class="grid" markdown>
|
||||
```c title="Right"
|
||||
if (p1 != NULL)
|
||||
if (p2 == NULL)
|
||||
|
||||
if (i1 != 0)
|
||||
if (i2 == 0)
|
||||
|
||||
if (c1 != '\0')
|
||||
if (c2 == '\0')
|
||||
```
|
||||
|
||||
```c title="Wrong"
|
||||
if (p1)
|
||||
if (!p2)
|
||||
|
||||
if (i1)
|
||||
if (!i2)
|
||||
|
||||
if (c1)
|
||||
if (!c2)
|
||||
```
|
||||
</div>
|
||||
|
||||
Do not check boolean values for equality:
|
||||
|
||||
```c
|
||||
gboolean b1, b2;
|
||||
```
|
||||
|
||||
<div class="grid" markdown>
|
||||
```c title="Right"
|
||||
if (b1)
|
||||
if (!b2)
|
||||
```
|
||||
|
||||
```c title="Wrong"
|
||||
if (b1 == TRUE)
|
||||
if (b2 == FALSE)
|
||||
```
|
||||
</div>
|
||||
|
||||
## Function calls
|
||||
|
||||
Always include a space between the name and the left parentheses when calling functions:
|
||||
|
||||
Reference in New Issue
Block a user