-
Notifications
You must be signed in to change notification settings - Fork 112
mistakes
Yegor Bugayenko edited this page Sep 11, 2013
·
32 revisions
Avoid composite names of variables, like timeOfDay
, firstItem
, or httpRequest
. I mean both class variables and in-method ones. A variable name should be long enough to avoid ambiguity in its scope of visibility, but not longer. A name should be a noun in singular or plural form, or its abbreviation, for example:
final List<String> names;
void sendThroughProxy(File file, Protocol proto);
private File content;
public HttpRequest request;
Sometimes you may have collisions between constructor parameters and in-class properties, when your constructor is saving incoming data into an instantiated object. In this case I recommend to use abbreviate by removing vowels, for example
public final class Message {
private String recipient;
public Message(final String rcpt) {
this.recipient = rcpt;
}
}
Don't calculate time with constants, like:
final long millis = min * 60 * 1000;
Instead, use TimeUnit
:
final long millis = TimeUnit.MINUTES.toMillis(2);
final long sec = TimeUnit.HOURS.toMinutes(1);