// Check to see if the employee is eligible for full benefitsif ((employee.flags& HOURLY_FLAG) && (employee.age>65))
Clean code:
if (employee.isEligibleForFullBenefits())
Good Comments
Legal Comments
// Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.// Released under the terms of the HNU General Public License version 2 or later.
Refer to a standard license or other external document rather than putting all the terms and conditions into the comment.
When its part of the standard library, or in code that you cannot alter, then a helpful clarifying comment can be useful.
publicvoidtestCompareTo() throws Exception {WikiPagePath a =PathParse.parse("PageA");WikiPagePath ab =PathParse.parse("PageA.PageB");WikiPagePath b =PathParse.parse("PageB");WikiPagePath aa =PathParse.parse("PageA.PageA");WikiPagePath bb =PathParse.parse("PageB.PageB");WikiPagePath ba =PathParse.parse("PageB.PageA");assertTrue(a.compareTo(a) ==0); // a == aassertTrue(a.compareTo(b) ==0); // a != aassertTrue(ab.compareTo(ab) ==0); // ab == abassertTrue(a.compareTo(b) ==-1); // a < bassertTrue(aa.compareTo(ab) ==-1); // aa < abassertTrue(ba.compareTo(bb) ==-1); // ba < bbassertTrue(b.compareTo(a) ==1); // b > aassertTrue(ab.compareTo(aa) ==1); // ab > aaassertTrue(bb.compareTo(ba) ==1); // bb > ba}
Warning of Consequences
// Don't run unless you have some time to kill.public oid _testWithReallyBigFile() {...}
TODO Comments
// TODO We expect this to go away when we do the checkout modelprotectedVersionInfomakeVersion() throws Exception {returnnull;}
Javadocs in Public APIs
Javadocs is used for generating the document automatically if the developers write the comments following its format.
Bad Comments
Redundant Comments
/** * The processor delay for this component. */protectedint backgroundProcessorDelay =-1;/** * The lifecycle event support for this compoent. */protectedLifecycleSupport lifecycle =newLifecycleSupport(this);...
Noise Comments
/** The day of the month. */privateint dayOfMonth;
/** * Returns the day of the month. * * @return the day of the month. */publicintgetDayOfMonth() {return dayOfMonth;}
Position Markers
// I'm here!!! ///////////////////////////////
Use them very sparingly, or your eyes will get used to ignoring it. Group the code in different files, or just by line breaks.