-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathConstantInConditional.qhelp
More file actions
34 lines (26 loc) · 1.38 KB
/
ConstantInConditional.qhelp
File metadata and controls
34 lines (26 loc) · 1.38 KB
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Using a constant value as a test in a conditional statement renders the statement pointless as only
one branch will be run regardless of any other factors.</p>
</overview>
<recommendation>
<p>If the conditional statement is required for debugging or similar then use a variable instead.
Otherwise, remove the conditional statement and any associated dead code.</p>
</recommendation>
<example>
<p>In the first example the <code>if</code> statement will always be executed and therefore can be removed. The
contents of the statement should be kept though.</p>
<p>In the second example the statement <code>l = 100</code> is never executed because <code>1 > 100</code> is always false.
However, it is likely that the intention was <code>l > 100</code> (the number '1' being misread as the letter 'l')
and that the test should be corrected, rather than deleted.
</p><sample src="ConstantInConditional.py" />
</example>
<references>
<li>Python: <a href="http://docs.python.org/reference/compound_stmts.html#the-if-statement">The If Statement</a>.</li>
<li>Python: <a href="http://docs.python.org/reference/compound_stmts.html#the-while-statement">The While Statement</a>.</li>
<li>Python: <a href="http://docs.python.org/reference/expressions.html#literals">Literals (constant values)</a>.</li>
</references>
</qhelp>