7. Explain Yourself in Code
//
check
if
the
user
is
administrator
if
(user.isRegistered
&&
user.privileges.equals(‘admin’))
{
...
}
vs.
if
(user.isAdmin)
{
...
}
13. Redundant Comments
/**
*
The
Loader
implementation
with
which
this
Container
is
*
associated.
*/
protected
Loader
loader
=
null;
/**
*
The
Logger
implementation
with
which
this
Container
is
*
associated.
*/
protected
Log
logger
=
null;
/**
*
The
Manager
implementation
with
which
this
Container
is
*
associated.
*/
protected
Manager
manager
=
null;
19. Commented-out Code
public
class
Program
{
static
void
Main(string[]
args)
{
/*
This
block
of
code
is
no
longer
needed
*
because
we
found
out
that
Y2K
was
a
hoax
*
and
our
systems
did
not
roll
over
to
1/1/1900
*/
//DateTime
today
=
DateTime.Today;
//if
(today
==
new
DateTime(1900,
1,
1))
//{
//
today
=
today.AddYears(100);
//
string
message
=
"The
date
has
been
fixed
for
Y2K.";
//
Console.WriteLine(message);
//}
}
}
20. HTML Tags in Comments
/**
*
Task
to
run
fit
tests.
This
task
runs
fitnesse
tests
and
publishes
the
results.
*
*
<pre>
*
Usage:
*
<taskdef
name="execute-‐fitnesse-‐tests"
classname="fitnesse.ant.ExecuteFitnesseTestsTask"
classpathref="classpath"
/>
*
OR
*
<taskdef
classpathref="classpath"
resource="tasks.properties"
/>
*
*
<execute-‐fitnesse-‐tests
suitepage="FitNesse.SuiteAcceptanceTests"
fitnesseport="8082"
resultsdir="${results.dir}"
resultshtmlpage="fit-‐results.html"
classpathref="classpath"
/>
*
</pre>
*/
23. Warning of Consequences Comments
//
Don’t
run
unless
you
//
have
some
time
to
kill
public
void
_testWithReallyBigFile()
{
writeLinesToFile(100000000);
response.setBody(testFile);
response.readyToSend(this);
String
responseString
=
output.toString();
assertSubString(“Content-‐Length:
100000000”,
responseString);
assertTrue(bytesSent
>
100000000)
}
25. TODO Comments
//
TODO:
Refactor
this
code
//
FIXME:
This
won't
work
if
the
file
is
missing.
//
XXX:
This
method
badly
needs
refactoring:
should
switch
by
core
type.