Skip to content

Instantly share code, notes, and snippets.

@micheljung
Created May 20, 2016 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micheljung/9c9800b44b6d587ffbf47b0c5b55adf5 to your computer and use it in GitHub Desktop.
Save micheljung/9c9800b44b6d587ffbf47b0c5b55adf5 to your computer and use it in GitHub Desktop.
An example of how comments and JavaDocs can be avoided
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