-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathCLinesOfComment.qhelp
More file actions
71 lines (57 loc) · 2.06 KB
/
CLinesOfComment.qhelp
File metadata and controls
71 lines (57 loc) · 2.06 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
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This metric measures the (absolute) number of comment lines for each method.
</p>
<p>
Whilst the absolute number of comment lines a method has is not always
especially meaningful when taken out of context, methods with very few
comment lines are almost undocumented and may be hard to understand.
</p>
</overview>
<recommendation>
<p>
Methods containing very few comments should be examined to see whether or not
they need more documentation. At a minimum, most methods (aside from getters,
setters and other trivial methods) usually benefit from at least a brief
comment as to their purpose. Less trivial methods can often be improved by
adding appropriate comments to communicate the programmer's intent, or to
summarize what a bit of code does. (See [McConnell] for more on writing good
comments.)
</p>
<p>
There are some cases, however, where adding more comments should not be the
main focus of refactoring:
</p>
<ul>
<li>
If your method is very long, the priority is to break it up into smaller
methods with sensible names that communicate intent. These new methods
should then be commented appropriately.
</li>
<li>
If your method is very hard to understand, you should redesign the way
it works to make things simpler. Tricky code is bad code - you shouldn't
document it, you should rewrite it (and then document it).
</li>
<li>
If your method is already absolutely clear and you don't have anything useful
to say, don't add meaningless comments. Comments are there to communicate
information that is not obvious from the code, not to repeat what's already
there. If you can't say something that couldn't be generated by an automatic
documentation generator (see [Atwood]), don't say anything.
</li>
</ul>
</recommendation>
<references>
<li>
J. Atwood. <a href="http://www.codinghorror.com/blog/2005/11/avoiding-undocumentation.html">Avoiding Undocumentation</a>. Published online, 2005.
</li>
<li>
S. McConnell. <em>Code Complete</em>, 2nd Edition. Microsoft Press, 2004.
</li>
</references>
</qhelp>