-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms.txt
85 lines (62 loc) · 1.9 KB
/
atoms.txt
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
1) Simple textual transpositions
Examples:
1) a=*c can be confused with a*=c which in turn can be confused with *a=c
Removal:
1) Parens/spacing:
- a=*b -> a = *b or a=(*b)
2) Implicit type-conversions as data manipulation:
Examples:
Assume: int a;
1) !!a can be confused with (a)
2) a/32*32 can be confused with (a)
Removal:
1) Use non-type-conversion techniques that accomplish the same thing
- !!a -> (a == 0)
- a/32*32 -> a - (a % 32)
2) Use explicit truncation operations:
- a/32*32 -> floor(a/32)*32
3) Ignoring conventions
Examples:
1) for (int i = 0; i < 3; printf("i: %d\n", i), i++) {}
2) *(b+1) can be confused with *b+1
Removal:
1) Use constructs as intended
- for (int i = 0; i < 3; printf("i: %d\n", i), i++) {}
for (int i = 0; i < 3; i++) { printf("i: %d\n", i); }
- *(b+1)
b[1]
4) Bitwise operations instead of logic
Examples:
1) 32&V3&V3/2 -> ???
Removal:
1) Use logical operators instead
- 32&V3&V3/2
32*(V3 >= '`' && V3 <= '\x7F'));
6) Using common values that have specific derivations:
Examples:
1) 32 has many meanings (which may make the value harder to remember or reason about)
Removal:
1) Show it's derivation
- 32 -> (2<<5) or (0x100/8) ('a' - 'A')
- 0 -> NULL or i-- or a-b
7) Common operations are distributed
Examples:
1) a<b?a|1:1|b
Removal:
1) Factor out common elements:
- a<b?a|1:1|b
(a<b?a:b)|1
8) Arithmetic used as logic
Examples:
1) a = (a > 3) * 5;
Removal:
1) Use an if statment
- a = (a > 3) * 5;
a = (a > 3) ? 0 : 5
9) Constant loop predicates
Examples:
1) while (i > 0 && j > 0) { i--; }
Removal:
1) Move constant condition to a surrounding if-statement instead
- while (i > 0 && j > 0) { i--; }
if (j > 0) { while (i > 0) { i--; } }