-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathVariableNameTooShort.qhelp
More file actions
36 lines (30 loc) · 1.67 KB
/
VariableNameTooShort.qhelp
File metadata and controls
36 lines (30 loc) · 1.67 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
35
36
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Source code with lots of short variable names is likely to be difficult to read.</p>
</overview>
<recommendation>
<p>There are some situations where short variable names may be acceptable. If the code is calculating a
mathematical formula with commonly accepted letters representing variables then it may be acceptable to use
single letter variable names because it makes it easier to compare the program with the original formula.
It is important to consider how long a variable will be used for when deciding how descriptive its name
needs to be. If the variable is declared on one line and only used on the next few then it may be clear
what its purpose is even if it has a short variable name. If a variable does not fit in one of these
exception categories then consider changing the names of the variables to make it more clear what their
purpose is.</p>
</recommendation>
<example>
<p>This example demonstrates the readability issues of short variables.</p>
<sample src="VariableNameTooShort.cs" />
<p>Here is an example of a program where using short variable names may be acceptable. This is because the
program is using a formula with commonly accepted letter substitutions and the life of the variables
is very short. It also includes a comment to explain the variables to someone who might not know what they
mean.</p>
<sample src="VariableNameTooShortAcceptable.cs" />
</example>
<references>
<li>Ars Technica. <a href="http://arstechnica.com/information-technology/2013/02/is-there-an-excuse-for-short-variable-names/">Is there an excuse for short variable names?</a>.</li>
</references>
</qhelp>