Created
May 20, 2016 11:02
-
-
Save micheljung/9c9800b44b6d587ffbf47b0c5b55adf5 to your computer and use it in GitHub Desktop.
An example of how comments and JavaDocs can be avoided
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AvoidComments { | |
/** | |
* Example of a superfluous comment. | |
*/ | |
private void badComment() { | |
// Time in milliseconds before exploding | |
long time = 5000; | |
} | |
/** | |
* Example of how comments can be avoided. | |
*/ | |
private void avoidedComment() { | |
long millisBeforeExploding = 5000; | |
} | |
/** | |
* Example of a Person class with unnecessary JavaDoc on methods. | |
*/ | |
class BadPerson { | |
private String name; | |
/** | |
* Returns the first name. | |
* | |
* @return a string containing the first name | |
*/ | |
public String getName() { | |
return name; | |
} | |
} | |
/** | |
* Example of a Person class that doesn't need JavaDoc on methods. | |
*/ | |
class GoodPerson { | |
private String firstName; | |
// There's no reason to comment that "getFirstName" returns the first name. | |
// There's also no reason to comment that it returns a string containing the first name. | |
public String getFirstName() { | |
return firstName; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment